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
ac7cf35b
Unverified
Commit
ac7cf35b
authored
Apr 24, 2021
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
missed a spot
parent
bd346030
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
16 deletions
+85
-16
useAllV3Routes.ts
src/hooks/useAllV3Routes.ts
+63
-0
useContract.ts
src/hooks/useContract.ts
+8
-1
yarn.lock
yarn.lock
+14
-15
No files found.
src/hooks/useAllV3Routes.ts
0 → 100644
View file @
ac7cf35b
import
{
ChainId
,
Currency
}
from
'
@uniswap/sdk-core
'
import
{
Pool
,
Route
}
from
'
@uniswap/v3-sdk
'
import
{
useMemo
}
from
'
react
'
import
{
wrappedCurrency
}
from
'
../utils/wrappedCurrency
'
import
{
useActiveWeb3React
}
from
'
./index
'
import
{
useV3SwapPools
}
from
'
./useV3SwapPools
'
function
computeAllRoutes
(
currencyIn
:
Currency
,
currencyOut
:
Currency
,
pools
:
Pool
[],
chainId
:
ChainId
,
currentPath
:
Pool
[]
=
[],
allPaths
:
Route
[]
=
[],
startCurrencyIn
:
Currency
=
currencyIn
,
maxHops
=
2
):
Route
[]
{
const
tokenIn
=
wrappedCurrency
(
currencyIn
,
chainId
)
const
tokenOut
=
wrappedCurrency
(
currencyOut
,
chainId
)
if
(
!
tokenIn
||
!
tokenOut
)
{
throw
new
Error
(
'
Could not wrap currencies
'
)
}
for
(
const
pool
of
pools
)
{
if
(
currentPath
.
indexOf
(
pool
)
!==
-
1
||
!
pool
.
involvesToken
(
tokenIn
))
continue
const
outputToken
=
pool
.
token0
.
equals
(
tokenIn
)
?
pool
.
token1
:
pool
.
token0
if
(
outputToken
.
equals
(
tokenOut
))
{
console
.
log
(
startCurrencyIn
,
[...
currentPath
,
pool
],
currencyOut
)
allPaths
.
push
(
new
Route
([...
currentPath
,
pool
],
startCurrencyIn
,
currencyOut
))
}
else
if
(
maxHops
>
1
)
{
computeAllRoutes
(
outputToken
,
currencyOut
,
pools
,
chainId
,
[...
currentPath
,
pool
],
allPaths
,
startCurrencyIn
,
maxHops
-
1
)
}
}
return
allPaths
}
/**
* Returns all the routes from an input currency to an output currency
* @param currencyIn the input currency
* @param currencyOut the output currency
*/
export
function
useAllV3Routes
(
currencyIn
?:
Currency
,
currencyOut
?:
Currency
):
Route
[]
{
const
{
chainId
}
=
useActiveWeb3React
()
const
{
pools
}
=
useV3SwapPools
(
currencyIn
,
currencyOut
)
return
useMemo
(()
=>
{
if
(
!
chainId
||
!
pools
||
!
currencyIn
||
!
currencyOut
)
return
[]
return
computeAllRoutes
(
currencyIn
,
currencyOut
,
pools
,
chainId
)
},
[
chainId
,
currencyIn
,
currencyOut
,
pools
])
}
src/hooks/useContract.ts
View file @
ac7cf35b
...
@@ -7,6 +7,7 @@ import { ChainId, WETH9 } from '@uniswap/sdk-core'
...
@@ -7,6 +7,7 @@ import { ChainId, WETH9 } from '@uniswap/sdk-core'
import
{
abi
as
IUniswapV2PairABI
}
from
'
@uniswap/v2-core/build/IUniswapV2Pair.json
'
import
{
abi
as
IUniswapV2PairABI
}
from
'
@uniswap/v2-core/build/IUniswapV2Pair.json
'
import
{
abi
as
V3FactoryABI
}
from
'
@uniswap/v3-core/artifacts/contracts/UniswapV3Factory.sol/UniswapV3Factory.json
'
import
{
abi
as
V3FactoryABI
}
from
'
@uniswap/v3-core/artifacts/contracts/UniswapV3Factory.sol/UniswapV3Factory.json
'
import
{
abi
as
V3PoolABI
}
from
'
@uniswap/v3-core/artifacts/contracts/UniswapV3Pool.sol/UniswapV3Pool.json
'
import
{
abi
as
V3PoolABI
}
from
'
@uniswap/v3-core/artifacts/contracts/UniswapV3Pool.sol/UniswapV3Pool.json
'
import
{
abi
as
QuoterABI
}
from
'
@uniswap/v3-periphery/artifacts/contracts/lens/Quoter.sol/Quoter.json
'
import
{
abi
as
V2MigratorABI
}
from
'
@uniswap/v3-periphery/artifacts/contracts/V3Migrator.sol/V3Migrator.json
'
import
{
abi
as
V2MigratorABI
}
from
'
@uniswap/v3-periphery/artifacts/contracts/V3Migrator.sol/V3Migrator.json
'
import
{
abi
as
TickLensABI
}
from
'
@uniswap/v3-periphery/artifacts/contracts/lens/TickLens.sol/TickLens.json
'
import
{
abi
as
TickLensABI
}
from
'
@uniswap/v3-periphery/artifacts/contracts/lens/TickLens.sol/TickLens.json
'
...
@@ -34,9 +35,10 @@ import {
...
@@ -34,9 +35,10 @@ import {
V3_CORE_FACTORY_ADDRESSES
,
V3_CORE_FACTORY_ADDRESSES
,
TICK_LENS_ADDRESSES
,
TICK_LENS_ADDRESSES
,
V2_MIGRATOR_ADDRESSES
,
V2_MIGRATOR_ADDRESSES
,
QUOTER_ADDRESSES
,
}
from
'
constants/v3
'
}
from
'
constants/v3
'
import
{
useMemo
}
from
'
react
'
import
{
useMemo
}
from
'
react
'
import
{
TickLens
,
UniswapV3Factory
,
UniswapV3Pool
}
from
'
types/v3
'
import
{
Quoter
,
TickLens
,
UniswapV3Factory
,
UniswapV3Pool
}
from
'
types/v3
'
import
{
NonfungiblePositionManager
}
from
'
types/v3/NonfungiblePositionManager
'
import
{
NonfungiblePositionManager
}
from
'
types/v3/NonfungiblePositionManager
'
import
{
V3Migrator
}
from
'
types/v3/V3Migrator
'
import
{
V3Migrator
}
from
'
types/v3/V3Migrator
'
import
{
getContract
}
from
'
utils
'
import
{
getContract
}
from
'
utils
'
...
@@ -162,6 +164,11 @@ export function useV3Pool(address: string | undefined): UniswapV3Pool | null {
...
@@ -162,6 +164,11 @@ export function useV3Pool(address: string | undefined): UniswapV3Pool | null {
return
useContract
(
address
,
V3PoolABI
)
as
UniswapV3Pool
|
null
return
useContract
(
address
,
V3PoolABI
)
as
UniswapV3Pool
|
null
}
}
export
function
useV3Quoter
():
Quoter
|
null
{
const
{
chainId
}
=
useActiveWeb3React
()
return
useContract
(
chainId
?
QUOTER_ADDRESSES
[
chainId
]
:
undefined
,
QuoterABI
)
as
Quoter
|
null
}
export
function
useTickLens
():
TickLens
|
null
{
export
function
useTickLens
():
TickLens
|
null
{
const
{
chainId
}
=
useActiveWeb3React
()
const
{
chainId
}
=
useActiveWeb3React
()
const
address
=
chainId
?
TICK_LENS_ADDRESSES
[
chainId
]
:
undefined
const
address
=
chainId
?
TICK_LENS_ADDRESSES
[
chainId
]
:
undefined
...
...
yarn.lock
View file @
ac7cf35b
...
@@ -4087,17 +4087,16 @@
...
@@ -4087,17 +4087,16 @@
resolved "https://registry.yarnpkg.com/@uniswap/merkle-distributor/-/merkle-distributor-1.0.1.tgz#dc3d911f65a860fc3f0cae074bdcd08ed6a27a4d"
resolved "https://registry.yarnpkg.com/@uniswap/merkle-distributor/-/merkle-distributor-1.0.1.tgz#dc3d911f65a860fc3f0cae074bdcd08ed6a27a4d"
integrity sha512-5gDiTI5hrXIh5UWTrxKYjw30QQDnpl8ckDSpefldNenDlYO1RKkdUYMYpvrqGi2r7YzLYTlO6+TDlNs6O7hDRw==
integrity sha512-5gDiTI5hrXIh5UWTrxKYjw30QQDnpl8ckDSpefldNenDlYO1RKkdUYMYpvrqGi2r7YzLYTlO6+TDlNs6O7hDRw==
"@uniswap/sdk-core@^1.0.
9
":
"@uniswap/sdk-core@^1.0.
10
":
version "1.0.
9
"
version "1.0.
10
"
resolved "https://registry.yarnpkg.com/@uniswap/sdk-core/-/sdk-core-1.0.
9.tgz#67e8d506e2c563f5183245ae9c32c54ac083479b
"
resolved "https://registry.yarnpkg.com/@uniswap/sdk-core/-/sdk-core-1.0.
10.tgz#a30118ac29319bd83113f9c90eab99f803ec9267
"
integrity sha512-
CWvDhN7mU+v786HEqAcyDhRMlLt9r6/Etgcduc36PlmmWk1Bb2XyK/UGMu/MD8cB9NlJ0h17WLx/X+CFg93iv
g==
integrity sha512-
8aD3xkzNDI3Ffh7PdLIcmraZr/6knqQuamVOv96EN8lhouEYH2ZuRbBWb7eZa/W7NwOLjlXM7XHi5gWJKzvbk
g==
dependencies:
dependencies:
"@ethersproject/address" "^5.0.2"
"@ethersproject/address" "^5.0.2"
big.js "^5.2.2"
big.js "^5.2.2"
decimal.js-light "^2.5.0"
decimal.js-light "^2.5.0"
jsbi "^3.1.4"
jsbi "^3.1.4"
tiny-invariant "^1.1.0"
tiny-invariant "^1.1.0"
tiny-warning "^1.0.3"
toformat "^2.0.0"
toformat "^2.0.0"
"@uniswap/token-lists@^1.0.0-beta.19":
"@uniswap/token-lists@^1.0.0-beta.19":
...
@@ -4123,14 +4122,14 @@
...
@@ -4123,14 +4122,14 @@
"@uniswap/lib" "1.1.1"
"@uniswap/lib" "1.1.1"
"@uniswap/v2-core" "1.0.0"
"@uniswap/v2-core" "1.0.0"
"@uniswap/v2-sdk@^1.0.
7
":
"@uniswap/v2-sdk@^1.0.
8
":
version "1.0.
7
"
version "1.0.
8
"
resolved "https://registry.yarnpkg.com/@uniswap/v2-sdk/-/v2-sdk-1.0.
7.tgz#442eadcf1283356dea7c96c21e24b70ede74ae4d
"
resolved "https://registry.yarnpkg.com/@uniswap/v2-sdk/-/v2-sdk-1.0.
8.tgz#6ea8a7a3861a3d2be536d2f5f1405d4a1e4dd024
"
integrity sha512-
HutwgAVEd2vxn+yNOHlO3Tu3oExudmgo/f6AzWjq99P0JcF3d8oi7+zJ/5/PSItk3hENZ1RVUaIvivV1uMNBGg
==
integrity sha512-
WmS2KXSfe251Q8cZ4Scb7NOapIC1llCzPLOmnz3Wiuce2wnGnx+IeQEdfeWj3N4o6Xd9QrUykXOx1B5mjn8nxA
==
dependencies:
dependencies:
"@ethersproject/address" "^5.0.0"
"@ethersproject/address" "^5.0.0"
"@ethersproject/solidity" "^5.0.0"
"@ethersproject/solidity" "^5.0.0"
"@uniswap/sdk-core" "^1.0.
9
"
"@uniswap/sdk-core" "^1.0.
10
"
tiny-invariant "^1.1.0"
tiny-invariant "^1.1.0"
tiny-warning "^1.0.3"
tiny-warning "^1.0.3"
...
@@ -4159,14 +4158,14 @@
...
@@ -4159,14 +4158,14 @@
"@uniswap/v2-core" "1.0.1"
"@uniswap/v2-core" "1.0.1"
"@uniswap/v3-core" "1.0.0-rc.2"
"@uniswap/v3-core" "1.0.0-rc.2"
"@uniswap/v3-sdk@^1.0.0-alpha.1
8
":
"@uniswap/v3-sdk@^1.0.0-alpha.1
9
":
version "1.0.0-alpha.1
8
"
version "1.0.0-alpha.1
9
"
resolved "https://registry.yarnpkg.com/@uniswap/v3-sdk/-/v3-sdk-1.0.0-alpha.1
8.tgz#53579f46f9939ed429f6e5d7fbf52bdd784145b6
"
resolved "https://registry.yarnpkg.com/@uniswap/v3-sdk/-/v3-sdk-1.0.0-alpha.1
9.tgz#b84d7f98278fd4be6488ebaca7f0d6cc2dec9ebd
"
integrity sha512-
CQNCfCKLoAWZHUjfCAu+TxLx64vjKHzgxP5uzM4aR61pFkINNCtRnChcJ96paORieezWwM411wW2VJ1DlC/nqQ
==
integrity sha512-
SJMFbAmqFlFhuYpA+bhuCqEa/TYFKtBu3js5GpbHQTttUO6fF1W4eFn6I4D+XCWsfx9T8WQKMNAxQsgyhIQDZA
==
dependencies:
dependencies:
"@ethersproject/abi" "^5.0.12"
"@ethersproject/abi" "^5.0.12"
"@ethersproject/solidity" "^5.0.9"
"@ethersproject/solidity" "^5.0.9"
"@uniswap/sdk-core" "^1.0.
9
"
"@uniswap/sdk-core" "^1.0.
10
"
"@uniswap/v3-periphery" "^1.0.0-beta.22"
"@uniswap/v3-periphery" "^1.0.0-beta.22"
tiny-invariant "^1.1.0"
tiny-invariant "^1.1.0"
tiny-warning "^1.0.3"
tiny-warning "^1.0.3"
...
...
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