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
3b6213f4
Unverified
Commit
3b6213f4
authored
Apr 26, 2021
by
Noah Zinsmeister
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'refs/remotes/origin/main'
parents
a5251f55
d846c83a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
25 deletions
+43
-25
useBestV3Trade.ts
src/hooks/useBestV3Trade.ts
+1
-1
updater.tsx
src/state/multicall/updater.tsx
+42
-24
No files found.
src/hooks/useBestV3Trade.ts
View file @
3b6213f4
...
@@ -115,7 +115,7 @@ export function useBestV3TradeExactOut(
...
@@ -115,7 +115,7 @@ export function useBestV3TradeExactOut(
])
])
},
[
amountOut
,
routes
])
},
[
amountOut
,
routes
])
const
quotesResults
=
useSingleContractMultipleData
(
quoter
,
'
quoteExact
In
put
'
,
quoteExactOutInputs
)
const
quotesResults
=
useSingleContractMultipleData
(
quoter
,
'
quoteExact
Out
put
'
,
quoteExactOutInputs
)
return
useMemo
(()
=>
{
return
useMemo
(()
=>
{
if
(
!
amountOut
||
!
currencyIn
||
quotesResults
.
some
(({
valid
})
=>
!
valid
))
{
if
(
!
amountOut
||
!
currencyIn
||
quotesResults
.
some
(({
valid
})
=>
!
valid
))
{
...
...
src/state/multicall/updater.tsx
View file @
3b6213f4
import
{
BigNumber
}
from
'
ethers
'
import
{
useEffect
,
useMemo
,
useRef
}
from
'
react
'
import
{
useEffect
,
useMemo
,
useRef
}
from
'
react
'
import
{
useDispatch
,
useSelector
}
from
'
react-redux
'
import
{
useDispatch
,
useSelector
}
from
'
react-redux
'
import
{
Multicall2
}
from
'
../../abis/types
'
import
{
Multicall2
}
from
'
../../abis/types
'
...
@@ -32,21 +31,24 @@ async function fetchChunk(
...
@@ -32,21 +31,24 @@ async function fetchChunk(
blockNumber
:
number
blockNumber
:
number
}
>
{
}
>
{
console
.
debug
(
'
Fetching chunk
'
,
multicall2Contract
,
chunk
,
minBlockNumber
)
console
.
debug
(
'
Fetching chunk
'
,
multicall2Contract
,
chunk
,
minBlockNumber
)
let
resultsBlockNumber
:
BigN
umber
let
resultsBlockNumber
:
n
umber
let
results
:
{
success
:
boolean
;
returnData
:
string
}[]
let
results
:
{
success
:
boolean
;
returnData
:
string
}[]
try
{
try
{
;[
resultsBlockNumber
,
,
results
]
=
await
multicall2Contract
.
callStatic
.
blockAndAggregate
(
const
{
blockNumber
,
returnData
}
=
await
multicall2Contract
.
callStatic
.
tryBlockAndAggregate
(
false
,
chunk
.
map
((
obj
)
=>
({
target
:
obj
.
address
,
callData
:
obj
.
callData
}))
chunk
.
map
((
obj
)
=>
({
target
:
obj
.
address
,
callData
:
obj
.
callData
}))
)
)
resultsBlockNumber
=
blockNumber
.
toNumber
()
results
=
returnData
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
debug
(
'
Failed to fetch chunk inside retry
'
,
error
)
console
.
debug
(
'
Failed to fetch chunk inside retry
'
,
error
)
throw
error
throw
error
}
}
if
(
resultsBlockNumber
.
toNumber
()
<
minBlockNumber
)
{
if
(
resultsBlockNumber
<
minBlockNumber
)
{
console
.
debug
(
`Fetched results for old block number:
${
resultsBlockNumber
.
toString
()}
vs.
${
minBlockNumber
}
`
)
console
.
debug
(
`Fetched results for old block number:
${
resultsBlockNumber
.
toString
()}
vs.
${
minBlockNumber
}
`
)
throw
new
RetryableError
(
'
Fetched for old block number
'
)
throw
new
RetryableError
(
'
Fetched for old block number
'
)
}
}
return
{
results
,
blockNumber
:
resultsBlockNumber
.
toNumber
()
}
return
{
results
,
blockNumber
:
resultsBlockNumber
}
}
}
/**
/**
...
@@ -175,27 +177,43 @@ export default function Updater(): null {
...
@@ -175,27 +177,43 @@ export default function Updater(): null {
const
slice
=
outdatedCallKeys
.
slice
(
firstCallKeyIndex
,
lastCallKeyIndex
)
const
slice
=
outdatedCallKeys
.
slice
(
firstCallKeyIndex
,
lastCallKeyIndex
)
dispatch
(
// split the returned slice into errors and success
updateMulticallResults
({
const
{
erroredCalls
,
results
}
=
slice
.
reduce
<
{
chainId
,
erroredCalls
:
Call
[]
results
:
slice
.
reduce
<
{
[
callKey
:
string
]:
string
|
null
}
>
((
memo
,
callKey
,
i
)
=>
{
results
:
{
[
callKey
:
string
]:
string
|
null
}
}
>
(
(
memo
,
callKey
,
i
)
=>
{
if
(
returnData
[
i
].
success
)
{
if
(
returnData
[
i
].
success
)
{
memo
[
callKey
]
=
returnData
[
i
].
returnData
??
null
memo
.
results
[
callKey
]
=
returnData
[
i
].
returnData
??
null
}
else
{
memo
.
erroredCalls
.
push
(
parseCallKey
(
callKey
))
}
}
return
memo
return
memo
},
{}),
},
{
erroredCalls
:
[],
results
:
{}
}
)
// dispatch any new results
if
(
Object
.
keys
(
results
).
length
>
0
)
dispatch
(
updateMulticallResults
({
chainId
,
results
,
blockNumber
:
fetchBlockNumber
,
blockNumber
:
fetchBlockNumber
,
})
})
)
)
// todo: dispatch an error for each call that failed, i.e. returnData[i].success === false
// dispatch any errored calls
// dispatch(
if
(
erroredCalls
.
length
>
0
)
{
// errorFetchingMulticallResults({
console
.
debug
(
'
Errored calls
'
,
erroredCalls
)
// calls: // todo: compute this,
dispatch
(
// chainId,
errorFetchingMulticallResults
({
// fetchingBlockNumber: latestBlockNumber,
calls
:
erroredCalls
,
// })
chainId
,
// )
fetchingBlockNumber
:
latestBlockNumber
,
})
)
}
})
})
.
catch
((
error
:
any
)
=>
{
.
catch
((
error
:
any
)
=>
{
if
(
error
instanceof
CancelledError
)
{
if
(
error
instanceof
CancelledError
)
{
...
...
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