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
5f64149f
Unverified
Commit
5f64149f
authored
Mar 15, 2023
by
Zach Pomerantz
Committed by
GitHub
Mar 15, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: trace quote (#6160)
* feat: trace quote * fix: include more data
parent
7115729e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
24 deletions
+48
-24
slice.ts
src/state/routing/slice.ts
+48
-24
No files found.
src/state/routing/slice.ts
View file @
5f64149f
...
...
@@ -5,6 +5,7 @@ import { RPC_PROVIDERS } from 'constants/providers'
import
{
getClientSideQuote
,
toSupportedChainId
}
from
'
lib/hooks/routing/clientSideSmartOrderRouter
'
import
ms
from
'
ms.macro
'
import
qs
from
'
qs
'
import
{
trace
}
from
'
tracing
'
import
{
GetQuoteResult
}
from
'
./types
'
...
...
@@ -64,34 +65,59 @@ const PRICE_PARAMS = {
distributionPercent
:
100
,
}
interface
GetQuoteArgs
{
tokenInAddress
:
string
tokenInChainId
:
ChainId
tokenInDecimals
:
number
tokenInSymbol
?:
string
tokenOutAddress
:
string
tokenOutChainId
:
ChainId
tokenOutDecimals
:
number
tokenOutSymbol
?:
string
amount
:
string
routerPreference
:
RouterPreference
type
:
'
exactIn
'
|
'
exactOut
'
}
export
const
routingApi
=
createApi
({
reducerPath
:
'
routingApi
'
,
baseQuery
:
fetchBaseQuery
({
baseUrl
:
'
https://api.uniswap.org/v1/
'
,
}),
endpoints
:
(
build
)
=>
({
getQuote
:
build
.
query
<
GetQuoteResult
,
{
tokenInAddress
:
string
tokenInChainId
:
ChainId
tokenInDecimals
:
number
tokenInSymbol
?:
string
tokenOutAddress
:
string
tokenOutChainId
:
ChainId
tokenOutDecimals
:
number
tokenOutSymbol
?:
string
amount
:
string
routerPreference
:
RouterPreference
type
:
'
exactIn
'
|
'
exactOut
'
}
>
({
getQuote
:
build
.
query
<
GetQuoteResult
,
GetQuoteArgs
>
({
async
onQueryStarted
(
args
:
GetQuoteArgs
,
{
queryFulfilled
})
{
trace
(
'
quote
'
,
async
({
setTraceError
,
setTraceStatus
})
=>
{
try
{
await
queryFulfilled
}
catch
(
error
:
unknown
)
{
if
(
error
&&
typeof
error
===
'
object
'
&&
'
error
'
in
error
)
{
const
queryError
=
(
error
as
Record
<
'
error
'
,
FetchBaseQueryError
>
).
error
if
(
typeof
queryError
.
status
===
'
number
'
)
{
setTraceStatus
(
queryError
.
status
)
}
setTraceError
(
queryError
)
}
else
{
throw
error
}
}
},
{
data
:
{
...
args
,
isPrice
:
args
.
routerPreference
===
RouterPreference
.
PRICE
,
isAutoRouter
:
args
.
routerPreference
===
RouterPreference
.
API
,
},
tags
:
{
is_widget
:
false
},
}
)
},
async
queryFn
(
args
,
_api
,
_extraOptions
,
fetch
)
{
const
{
tokenInAddress
,
tokenInChainId
,
tokenOutAddress
,
tokenOutChainId
,
amount
,
routerPreference
,
type
}
=
args
let
result
try
{
if
(
routerPreference
===
RouterPreference
.
API
)
{
const
query
=
qs
.
stringify
({
...
...
@@ -103,10 +129,10 @@ export const routingApi = createApi({
amount
,
type
,
})
re
sult
=
await
fetch
(
`quote?
${
query
}
`
)
re
turn
(
await
fetch
(
`quote?
${
query
}
`
))
as
{
data
:
GetQuoteResult
}
|
{
error
:
FetchBaseQueryError
}
}
else
{
const
router
=
getRouter
(
args
.
tokenInChainId
)
re
sult
=
await
getClientSideQuote
(
re
turn
await
getClientSideQuote
(
args
,
router
,
// TODO(zzmp): Use PRICE_PARAMS for RouterPreference.PRICE.
...
...
@@ -114,12 +140,10 @@ export const routingApi = createApi({
CLIENT_PARAMS
)
}
return
{
data
:
result
.
data
as
GetQuoteResult
}
}
catch
(
e
)
{
}
catch
(
error
)
{
// TODO: fall back to client-side quoter when auto router fails.
// deprecate 'legacy' v2/v3 routers first.
return
{
error
:
e
as
FetchBaseQueryError
}
return
{
error
:
{
status
:
'
CUSTOM_ERROR
'
,
error
:
error
.
toString
(),
data
:
error
}
}
}
},
keepUnusedDataFor
:
ms
`10s`
,
...
...
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