Skip to content

Commit

Permalink
fix(permit): report wrong permit to sentry for limit and swap flows (#…
Browse files Browse the repository at this point in the history
…3565)

* feat: add utils fn reportPermitWithDefaultSigner

* fix: report to sentry incorrect permit for both swap and limit orders

* fix: remove signer address `0x` prefix which is not included in the calldata
  • Loading branch information
alfetopito authored Jan 3, 2024
1 parent 53402e8 commit 7067919
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { reportPermitWithDefaultSigner } from '@cowprotocol/common-utils'
import { OrderClass } from '@cowprotocol/cow-sdk'
import { PERMIT_SIGNER, isSupportedPermitInfo } from '@cowprotocol/permit-utils'
import { isSupportedPermitInfo } from '@cowprotocol/permit-utils'
import { Percent } from '@uniswap/sdk-core'

import * as Sentry from '@sentry/browser'

import { PriceImpact } from 'legacy/hooks/usePriceImpact'
import { partialOrderUpdate } from 'legacy/state/orders/utils'
import { signAndPostOrder } from 'legacy/utils/trade'
Expand All @@ -13,6 +12,7 @@ import { PriceImpactDeclineError, TradeFlowContext } from 'modules/limitOrders/s
import { LimitOrdersSettingsState } from 'modules/limitOrders/state/limitOrdersSettingsAtom'
import { calculateLimitOrdersDeadline } from 'modules/limitOrders/utils/calculateLimitOrdersDeadline'
import { handlePermit } from 'modules/permit'
import { appDataContainsPermitSigner } from 'modules/permit/utils/appDataContainsPermitSigner'
import { presignOrderStep } from 'modules/swap/services/swapFlow/steps/presignOrderStep'
import { addPendingOrderStep } from 'modules/trade/utils/addPendingOrderStep'
import { SwapFlowAnalyticsContext, tradeFlowAnalytics } from 'modules/trade/utils/analytics'
Expand Down Expand Up @@ -70,12 +70,8 @@ export async function tradeFlow(
generatePermitHook,
})

if (postOrderParams.appData.fullAppData.includes(PERMIT_SIGNER.address)) {
// report this to sentry if we ever use the default signer in the permit
Sentry.captureException('User signed the permit using PERMIT_SIGNER instead of their account', {
tags: { errorType: 'permitWithDefaultSigner' },
contexts: { params: { account } },
})
if (appDataContainsPermitSigner(postOrderParams.appData.fullAppData)) {
reportPermitWithDefaultSigner(postOrderParams)
}

logTradeFlow('LIMIT ORDER FLOW', 'STEP 3: send transaction')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { PERMIT_SIGNER } from '@cowprotocol/permit-utils'

export function appDataContainsPermitSigner(fullAppData: string | undefined): boolean {
if (!fullAppData) {
return false
}

const signerAddressWithoutPrefix = PERMIT_SIGNER.address.slice(2).toLowerCase()

return fullAppData.toLowerCase().includes(signerAddressWithoutPrefix)
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { reportPermitWithDefaultSigner } from '@cowprotocol/common-utils'
import { isSupportedPermitInfo } from '@cowprotocol/permit-utils'
import { Percent } from '@uniswap/sdk-core'

Expand All @@ -6,6 +7,7 @@ import { partialOrderUpdate } from 'legacy/state/orders/utils'
import { signAndPostOrder } from 'legacy/utils/trade'

import { handlePermit } from 'modules/permit'
import { appDataContainsPermitSigner } from 'modules/permit/utils/appDataContainsPermitSigner'
import { addPendingOrderStep } from 'modules/trade/utils/addPendingOrderStep'
import { tradeFlowAnalytics } from 'modules/trade/utils/analytics'
import { logTradeFlow } from 'modules/trade/utils/logger'
Expand Down Expand Up @@ -36,6 +38,11 @@ export async function swapFlow(
permitInfo: input.permitInfo,
generatePermitHook: input.generatePermitHook,
})

if (appDataContainsPermitSigner(input.orderParams.appData.fullAppData)) {
reportPermitWithDefaultSigner(input.orderParams)
}

input.swapConfirmManager.permitSigned()

logTradeFlow('SWAP FLOW', 'STEP 3: send transaction')
Expand Down
1 change: 1 addition & 0 deletions libs/common-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ export * from './maxAmountSpend'
export * from './getWrappedToken'
export * from './capitalizeFirstLetter'
export * from './jotai/atomWithPartialUpdate'
export * from './sentry'
9 changes: 9 additions & 0 deletions libs/common-utils/src/sentry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as Sentry from '@sentry/browser'

export function reportPermitWithDefaultSigner(params: Record<any, any>): void {
// report this to sentry if we ever use the default signer in the permit
Sentry.captureException('User signed the permit using PERMIT_SIGNER instead of their account', {
tags: { errorType: 'permitWithDefaultSigner' },
contexts: { params },
})
}

0 comments on commit 7067919

Please sign in to comment.