Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
f2c5a7c0
Unverified
Commit
f2c5a7c0
authored
Jan 19, 2023
by
Zach Pomerantz
Committed by
GitHub
Jan 19, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: track universal router swaps and err on wallet-edited calldata (#5864)
fix: track universal router swaps
parent
fb527709
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
3 deletions
+24
-3
useUniversalRouter.ts
src/hooks/useUniversalRouter.ts
+24
-3
No files found.
src/hooks/useUniversalRouter.ts
View file @
f2c5a7c0
import
{
TransactionResponse
}
from
'
@ethersproject/abstract-provider
'
import
{
BigNumber
}
from
'
@ethersproject/bignumber
'
import
{
t
}
from
'
@lingui/macro
'
import
{
sendAnalyticsEvent
}
from
'
@uniswap/analytics
'
import
{
SwapEventName
}
from
'
@uniswap/analytics-events
'
import
{
Trade
}
from
'
@uniswap/router-sdk
'
import
{
Currency
,
Percent
,
TradeType
}
from
'
@uniswap/sdk-core
'
import
{
SwapRouter
,
UNIVERSAL_ROUTER_ADDRESS
}
from
'
@uniswap/universal-router-sdk
'
import
{
FeeOptions
,
toHex
}
from
'
@uniswap/v3-sdk
'
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
formatSwapSignedAnalyticsEventProperties
}
from
'
lib/utils/analytics
'
import
{
useCallback
}
from
'
react
'
import
{
calculateGasMargin
}
from
'
utils/calculateGasMargin
'
import
isZero
from
'
utils/isZero
'
...
...
@@ -12,6 +16,8 @@ import { swapErrorToUserReadableMessage } from 'utils/swapErrorToUserReadableMes
import
{
PermitSignature
}
from
'
./usePermitAllowance
'
class
InvalidSwapError
extends
Error
{}
interface
SwapOptions
{
slippageTolerance
:
Percent
deadline
?:
BigNumber
...
...
@@ -55,11 +61,26 @@ export function useUniversalRouterSwapCallback(
gasEstimate
=
await
provider
.
estimateGas
(
tx
)
}
const
gasLimit
=
calculateGasMargin
(
gasEstimate
)
const
response
=
await
provider
.
getSigner
().
sendTransaction
({
...
tx
,
gasLimit
})
const
response
=
await
provider
.
getSigner
()
.
sendTransaction
({
...
tx
,
gasLimit
})
.
then
((
response
)
=>
{
sendAnalyticsEvent
(
SwapEventName
.
SWAP_SIGNED
,
formatSwapSignedAnalyticsEventProperties
({
trade
,
txHash
:
response
.
hash
})
)
if
(
tx
.
data
!==
response
.
data
)
{
sendAnalyticsEvent
(
SwapEventName
.
SWAP_MODIFIED_IN_WALLET
,
{
txHash
:
response
.
hash
})
throw
new
InvalidSwapError
(
t
`Your swap was modified through your wallet. If this was a mistake, please cancel immediately or risk losing your funds.`
)
}
return
response
})
return
response
}
catch
(
swapError
:
unknown
)
{
const
message
=
swapErrorToUserReadableMessage
(
swapError
)
throw
new
Error
(
message
)
if
(
swapError
instanceof
InvalidSwapError
)
throw
swapError
throw
new
Error
(
swapErrorToUserReadableMessage
(
swapError
)
)
}
},
[
account
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment