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
9492e737
Unverified
Commit
9492e737
authored
May 29, 2020
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore(multicall/migrate): move some v1 stuff around for migrate
parent
8a6a10be
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
1040 additions
and
34 deletions
+1040
-34
index.ts
src/constants/index.ts
+1
-3
index.ts
src/constants/v1/index.ts
+9
-0
v1_exchange.json
src/constants/v1/v1_exchange.json
+971
-0
v1_factory.json
src/constants/v1/v1_factory.json
+7
-14
V1.ts
src/data/V1.ts
+15
-1
useContract.ts
src/hooks/useContract.ts
+7
-3
actions.ts
src/state/multicall/actions.ts
+2
-2
hooks.ts
src/state/multicall/hooks.ts
+28
-11
No files found.
src/constants/index.ts
View file @
9492e737
import
{
ChainId
,
Token
,
WETH
,
JSBI
,
Percent
}
from
'
@uniswap/sdk
'
import
{
ChainId
,
JSBI
,
Percent
,
Token
,
WETH
}
from
'
@uniswap/sdk
'
import
{
fortmatic
,
injected
,
portis
,
walletconnect
,
walletlink
}
from
'
../connectors
'
export
const
V1_FACTORY_ADDRESS
=
'
0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95
'
export
const
ROUTER_ADDRESS
=
'
0xf164fC0Ec4E93095b804a4795bBe1e041497b92a
'
// used for display in the default list when adding liquidity
...
...
src/constants/v1/index.ts
0 → 100644
View file @
9492e737
import
{
Interface
}
from
'
@ethersproject/abi
'
import
V1_EXCHANGE_ABI
from
'
./v1_exchange.json
'
import
V1_FACTORY_ABI
from
'
./v1_factory.json
'
const
V1_FACTORY_ADDRESS
=
'
0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95
'
const
V1_FACTORY_INTERFACE
=
new
Interface
(
V1_FACTORY_ABI
)
const
V1_EXCHANGE_INTERFACE
=
new
Interface
(
V1_EXCHANGE_ABI
)
export
{
V1_FACTORY_ADDRESS
,
V1_FACTORY_INTERFACE
,
V1_FACTORY_ABI
,
V1_EXCHANGE_INTERFACE
,
V1_EXCHANGE_ABI
}
src/constants/v1/v1_exchange.json
0 → 100644
View file @
9492e737
[
{
"name"
:
"TokenPurchase"
,
"inputs"
:
[
{
"type"
:
"address"
,
"name"
:
"buyer"
,
"indexed"
:
true
},
{
"type"
:
"uint256"
,
"name"
:
"eth_sold"
,
"indexed"
:
true
},
{
"type"
:
"uint256"
,
"name"
:
"tokens_bought"
,
"indexed"
:
true
}
],
"anonymous"
:
false
,
"type"
:
"event"
},
{
"name"
:
"EthPurchase"
,
"inputs"
:
[
{
"type"
:
"address"
,
"name"
:
"buyer"
,
"indexed"
:
true
},
{
"type"
:
"uint256"
,
"name"
:
"tokens_sold"
,
"indexed"
:
true
},
{
"type"
:
"uint256"
,
"name"
:
"eth_bought"
,
"indexed"
:
true
}
],
"anonymous"
:
false
,
"type"
:
"event"
},
{
"name"
:
"AddLiquidity"
,
"inputs"
:
[
{
"type"
:
"address"
,
"name"
:
"provider"
,
"indexed"
:
true
},
{
"type"
:
"uint256"
,
"name"
:
"eth_amount"
,
"indexed"
:
true
},
{
"type"
:
"uint256"
,
"name"
:
"token_amount"
,
"indexed"
:
true
}
],
"anonymous"
:
false
,
"type"
:
"event"
},
{
"name"
:
"RemoveLiquidity"
,
"inputs"
:
[
{
"type"
:
"address"
,
"name"
:
"provider"
,
"indexed"
:
true
},
{
"type"
:
"uint256"
,
"name"
:
"eth_amount"
,
"indexed"
:
true
},
{
"type"
:
"uint256"
,
"name"
:
"token_amount"
,
"indexed"
:
true
}
],
"anonymous"
:
false
,
"type"
:
"event"
},
{
"name"
:
"Transfer"
,
"inputs"
:
[
{
"type"
:
"address"
,
"name"
:
"_from"
,
"indexed"
:
true
},
{
"type"
:
"address"
,
"name"
:
"_to"
,
"indexed"
:
true
},
{
"type"
:
"uint256"
,
"name"
:
"_value"
,
"indexed"
:
false
}
],
"anonymous"
:
false
,
"type"
:
"event"
},
{
"name"
:
"Approval"
,
"inputs"
:
[
{
"type"
:
"address"
,
"name"
:
"_owner"
,
"indexed"
:
true
},
{
"type"
:
"address"
,
"name"
:
"_spender"
,
"indexed"
:
true
},
{
"type"
:
"uint256"
,
"name"
:
"_value"
,
"indexed"
:
false
}
],
"anonymous"
:
false
,
"type"
:
"event"
},
{
"name"
:
"setup"
,
"outputs"
:
[],
"inputs"
:
[
{
"type"
:
"address"
,
"name"
:
"token_addr"
}
],
"constant"
:
false
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"addLiquidity"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"min_liquidity"
},
{
"type"
:
"uint256"
,
"name"
:
"max_tokens"
},
{
"type"
:
"uint256"
,
"name"
:
"deadline"
}
],
"constant"
:
false
,
"payable"
:
true
,
"type"
:
"function"
},
{
"name"
:
"removeLiquidity"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"outA"
},
{
"type"
:
"uint256"
,
"name"
:
"outB"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"amount"
},
{
"type"
:
"uint256"
,
"name"
:
"min_eth"
},
{
"type"
:
"uint256"
,
"name"
:
"min_tokens"
},
{
"type"
:
"uint256"
,
"name"
:
"deadline"
}
],
"constant"
:
false
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"__default__"
,
"outputs"
:
[],
"inputs"
:
[],
"constant"
:
false
,
"payable"
:
true
,
"type"
:
"function"
},
{
"name"
:
"ethToTokenSwapInput"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"min_tokens"
},
{
"type"
:
"uint256"
,
"name"
:
"deadline"
}
],
"constant"
:
false
,
"payable"
:
true
,
"type"
:
"function"
},
{
"name"
:
"ethToTokenTransferInput"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"min_tokens"
},
{
"type"
:
"uint256"
,
"name"
:
"deadline"
},
{
"type"
:
"address"
,
"name"
:
"recipient"
}
],
"constant"
:
false
,
"payable"
:
true
,
"type"
:
"function"
},
{
"name"
:
"ethToTokenSwapOutput"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"tokens_bought"
},
{
"type"
:
"uint256"
,
"name"
:
"deadline"
}
],
"constant"
:
false
,
"payable"
:
true
,
"type"
:
"function"
},
{
"name"
:
"ethToTokenTransferOutput"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"tokens_bought"
},
{
"type"
:
"uint256"
,
"name"
:
"deadline"
},
{
"type"
:
"address"
,
"name"
:
"recipient"
}
],
"constant"
:
false
,
"payable"
:
true
,
"type"
:
"function"
},
{
"name"
:
"tokenToEthSwapInput"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"tokens_sold"
},
{
"type"
:
"uint256"
,
"name"
:
"min_eth"
},
{
"type"
:
"uint256"
,
"name"
:
"deadline"
}
],
"constant"
:
false
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"tokenToEthTransferInput"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"tokens_sold"
},
{
"type"
:
"uint256"
,
"name"
:
"min_eth"
},
{
"type"
:
"uint256"
,
"name"
:
"deadline"
},
{
"type"
:
"address"
,
"name"
:
"recipient"
}
],
"constant"
:
false
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"tokenToEthSwapOutput"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"eth_bought"
},
{
"type"
:
"uint256"
,
"name"
:
"max_tokens"
},
{
"type"
:
"uint256"
,
"name"
:
"deadline"
}
],
"constant"
:
false
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"tokenToEthTransferOutput"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"eth_bought"
},
{
"type"
:
"uint256"
,
"name"
:
"max_tokens"
},
{
"type"
:
"uint256"
,
"name"
:
"deadline"
},
{
"type"
:
"address"
,
"name"
:
"recipient"
}
],
"constant"
:
false
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"tokenToTokenSwapInput"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"tokens_sold"
},
{
"type"
:
"uint256"
,
"name"
:
"min_tokens_bought"
},
{
"type"
:
"uint256"
,
"name"
:
"min_eth_bought"
},
{
"type"
:
"uint256"
,
"name"
:
"deadline"
},
{
"type"
:
"address"
,
"name"
:
"token_addr"
}
],
"constant"
:
false
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"tokenToTokenTransferInput"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"tokens_sold"
},
{
"type"
:
"uint256"
,
"name"
:
"min_tokens_bought"
},
{
"type"
:
"uint256"
,
"name"
:
"min_eth_bought"
},
{
"type"
:
"uint256"
,
"name"
:
"deadline"
},
{
"type"
:
"address"
,
"name"
:
"recipient"
},
{
"type"
:
"address"
,
"name"
:
"token_addr"
}
],
"constant"
:
false
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"tokenToTokenSwapOutput"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"tokens_bought"
},
{
"type"
:
"uint256"
,
"name"
:
"max_tokens_sold"
},
{
"type"
:
"uint256"
,
"name"
:
"max_eth_sold"
},
{
"type"
:
"uint256"
,
"name"
:
"deadline"
},
{
"type"
:
"address"
,
"name"
:
"token_addr"
}
],
"constant"
:
false
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"tokenToTokenTransferOutput"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"tokens_bought"
},
{
"type"
:
"uint256"
,
"name"
:
"max_tokens_sold"
},
{
"type"
:
"uint256"
,
"name"
:
"max_eth_sold"
},
{
"type"
:
"uint256"
,
"name"
:
"deadline"
},
{
"type"
:
"address"
,
"name"
:
"recipient"
},
{
"type"
:
"address"
,
"name"
:
"token_addr"
}
],
"constant"
:
false
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"tokenToExchangeSwapInput"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"tokens_sold"
},
{
"type"
:
"uint256"
,
"name"
:
"min_tokens_bought"
},
{
"type"
:
"uint256"
,
"name"
:
"min_eth_bought"
},
{
"type"
:
"uint256"
,
"name"
:
"deadline"
},
{
"type"
:
"address"
,
"name"
:
"exchange_addr"
}
],
"constant"
:
false
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"tokenToExchangeTransferInput"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"tokens_sold"
},
{
"type"
:
"uint256"
,
"name"
:
"min_tokens_bought"
},
{
"type"
:
"uint256"
,
"name"
:
"min_eth_bought"
},
{
"type"
:
"uint256"
,
"name"
:
"deadline"
},
{
"type"
:
"address"
,
"name"
:
"recipient"
},
{
"type"
:
"address"
,
"name"
:
"exchange_addr"
}
],
"constant"
:
false
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"tokenToExchangeSwapOutput"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"tokens_bought"
},
{
"type"
:
"uint256"
,
"name"
:
"max_tokens_sold"
},
{
"type"
:
"uint256"
,
"name"
:
"max_eth_sold"
},
{
"type"
:
"uint256"
,
"name"
:
"deadline"
},
{
"type"
:
"address"
,
"name"
:
"exchange_addr"
}
],
"constant"
:
false
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"tokenToExchangeTransferOutput"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"tokens_bought"
},
{
"type"
:
"uint256"
,
"name"
:
"max_tokens_sold"
},
{
"type"
:
"uint256"
,
"name"
:
"max_eth_sold"
},
{
"type"
:
"uint256"
,
"name"
:
"deadline"
},
{
"type"
:
"address"
,
"name"
:
"recipient"
},
{
"type"
:
"address"
,
"name"
:
"exchange_addr"
}
],
"constant"
:
false
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"getEthToTokenInputPrice"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"eth_sold"
}
],
"constant"
:
true
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"getEthToTokenOutputPrice"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"tokens_bought"
}
],
"constant"
:
true
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"getTokenToEthInputPrice"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"tokens_sold"
}
],
"constant"
:
true
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"getTokenToEthOutputPrice"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"eth_bought"
}
],
"constant"
:
true
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"tokenAddress"
,
"outputs"
:
[
{
"type"
:
"address"
,
"name"
:
"out"
}
],
"inputs"
:
[],
"constant"
:
true
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"factoryAddress"
,
"outputs"
:
[
{
"type"
:
"address"
,
"name"
:
"out"
}
],
"inputs"
:
[],
"constant"
:
true
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"balanceOf"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"address"
,
"name"
:
"_owner"
}
],
"constant"
:
true
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"transfer"
,
"outputs"
:
[
{
"type"
:
"bool"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"address"
,
"name"
:
"_to"
},
{
"type"
:
"uint256"
,
"name"
:
"_value"
}
],
"constant"
:
false
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"transferFrom"
,
"outputs"
:
[
{
"type"
:
"bool"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"address"
,
"name"
:
"_from"
},
{
"type"
:
"address"
,
"name"
:
"_to"
},
{
"type"
:
"uint256"
,
"name"
:
"_value"
}
],
"constant"
:
false
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"approve"
,
"outputs"
:
[
{
"type"
:
"bool"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"address"
,
"name"
:
"_spender"
},
{
"type"
:
"uint256"
,
"name"
:
"_value"
}
],
"constant"
:
false
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"allowance"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[
{
"type"
:
"address"
,
"name"
:
"_owner"
},
{
"type"
:
"address"
,
"name"
:
"_spender"
}
],
"constant"
:
true
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"name"
,
"outputs"
:
[
{
"type"
:
"bytes32"
,
"name"
:
"out"
}
],
"inputs"
:
[],
"constant"
:
true
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"symbol"
,
"outputs"
:
[
{
"type"
:
"bytes32"
,
"name"
:
"out"
}
],
"inputs"
:
[],
"constant"
:
true
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"decimals"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[],
"constant"
:
true
,
"payable"
:
false
,
"type"
:
"function"
},
{
"name"
:
"totalSupply"
,
"outputs"
:
[
{
"type"
:
"uint256"
,
"name"
:
"out"
}
],
"inputs"
:
[],
"constant"
:
true
,
"payable"
:
false
,
"type"
:
"function"
}
]
\ No newline at end of file
src/constants/
abis
/v1_factory.json
→
src/constants/
v1
/v1_factory.json
View file @
9492e737
...
...
@@ -14,8 +14,7 @@
"inputs"
:
[{
"type"
:
"address", "name"
:
"template"
}],
"constant"
:
false
,
"payable"
:
false
,
"type"
:
"function"
,
"gas"
:
35725
"type"
:
"function"
},
{
"name"
:
"createExchange"
,
...
...
@@ -23,8 +22,7 @@
"inputs"
:
[{
"type"
:
"address", "name"
:
"token"
}],
"constant"
:
false
,
"payable"
:
false
,
"type"
:
"function"
,
"gas"
:
187911
"type"
:
"function"
},
{
"name"
:
"getExchange"
,
...
...
@@ -32,8 +30,7 @@
"inputs"
:
[{
"type"
:
"address", "name"
:
"token"
}],
"constant"
:
true
,
"payable"
:
false
,
"type"
:
"function"
,
"gas"
:
715
"type"
:
"function"
},
{
"name"
:
"getToken"
,
...
...
@@ -41,8 +38,7 @@
"inputs"
:
[{
"type"
:
"address", "name"
:
"exchange"
}],
"constant"
:
true
,
"payable"
:
false
,
"type"
:
"function"
,
"gas"
:
745
"type"
:
"function"
},
{
"name"
:
"getTokenWithId"
,
...
...
@@ -50,8 +46,7 @@
"inputs"
:
[{
"type"
:
"uint256", "name"
:
"token_id"
}],
"constant"
:
true
,
"payable"
:
false
,
"type"
:
"function"
,
"gas"
:
736
"type"
:
"function"
},
{
"name"
:
"exchangeTemplate"
,
...
...
@@ -59,8 +54,7 @@
"inputs"
:
[],
"constant"
:
true
,
"payable"
:
false
,
"type"
:
"function"
,
"gas"
:
633
"type"
:
"function"
},
{
"name"
:
"tokenCount"
,
...
...
@@ -68,7 +62,6 @@
"inputs"
:
[],
"constant"
:
true
,
"payable"
:
false
,
"type"
:
"function"
,
"gas"
:
663
"type"
:
"function"
}
]
src/data/V1.ts
View file @
9492e737
...
...
@@ -2,7 +2,7 @@ import { ChainId, Pair, Percent, Route, Token, TokenAmount, Trade, TradeType, WE
import
{
useMemo
}
from
'
react
'
import
{
useActiveWeb3React
}
from
'
../hooks
'
import
{
useV1FactoryContract
}
from
'
../hooks/useContract
'
import
{
useSingleCallResult
}
from
'
../state/multicall/hooks
'
import
{
NEVER_RELOAD
,
useSingleCallResult
,
useSingleContractMultipleData
}
from
'
../state/multicall/hooks
'
import
{
useETHBalances
,
useTokenBalance
}
from
'
../state/wallet/hooks
'
function
useV1PairAddress
(
tokenAddress
?:
string
):
string
|
undefined
{
...
...
@@ -29,6 +29,20 @@ function useMockV1Pair(token?: Token): MockV1Pair | undefined {
:
undefined
}
export
function
useAllV1ExchangeAddresses
():
string
[]
{
const
factory
=
useV1FactoryContract
()
const
exchangeCount
=
useSingleCallResult
(
factory
,
'
tokenCount
'
)?.
result
const
parsedCount
=
parseInt
(
exchangeCount
?.
toString
()
??
'
0
'
)
const
indices
=
[...
Array
(
parsedCount
).
keys
()].
map
(
ix
=>
[
ix
])
return
(
useSingleContractMultipleData
(
factory
,
'
getTokenWithId
'
,
indices
,
NEVER_RELOAD
)
?.
map
(({
result
})
=>
result
?.[
0
])
?.
filter
(
x
=>
x
)
??
[]
)
}
export
function
useV1TradeLinkIfBetter
(
isExactIn
?:
boolean
,
input
?:
Token
,
...
...
src/hooks/useContract.ts
View file @
9492e737
...
...
@@ -2,9 +2,8 @@ import { Contract } from '@ethersproject/contracts'
import
{
ChainId
}
from
'
@uniswap/sdk
'
import
{
abi
as
IUniswapV2PairABI
}
from
'
@uniswap/v2-core/build/IUniswapV2Pair.json
'
import
{
useMemo
}
from
'
react
'
import
{
V1_FACTORY_ADDRESS
}
from
'
../constants
'
import
ERC20_ABI
from
'
../constants/abis/erc20.json
'
import
IUniswapV1Factory
from
'
../constants/abis/v1_factory.json
'
import
{
V1_EXCHANGE_ABI
,
V1_FACTORY_ABI
,
V1_FACTORY_ADDRESS
}
from
'
../constants/v1
'
import
{
MULTICALL_ABI
,
MULTICALL_NETWORKS
}
from
'
../constants/multicall
'
import
{
getContract
}
from
'
../utils
'
import
{
useActiveWeb3React
}
from
'
./index
'
...
...
@@ -25,7 +24,12 @@ function useContract(address?: string, ABI?: any, withSignerIfPossible = true):
}
export
function
useV1FactoryContract
():
Contract
|
null
{
return
useContract
(
V1_FACTORY_ADDRESS
,
IUniswapV1Factory
,
false
)
const
{
chainId
}
=
useActiveWeb3React
()
return
useContract
(
chainId
===
1
?
V1_FACTORY_ADDRESS
:
undefined
,
V1_FACTORY_ABI
,
false
)
}
export
function
useV1ExchangeContract
(
address
:
string
):
Contract
|
null
{
return
useContract
(
address
,
V1_EXCHANGE_ABI
,
false
)
}
export
function
useTokenContract
(
tokenAddress
?:
string
,
withSignerIfPossible
=
true
):
Contract
|
null
{
...
...
src/state/multicall/actions.ts
View file @
9492e737
...
...
@@ -30,9 +30,9 @@ export function parseCallKey(callKey: string): Call {
}
}
interface
ListenerOptions
{
export
interface
ListenerOptions
{
// how often this data should be fetched, by default 1
blocksPerFetch
?:
number
readonly
blocksPerFetch
?:
number
}
export
const
addMulticallListeners
=
createAction
<
{
chainId
:
number
;
calls
:
Call
[];
options
?:
ListenerOptions
}
>
(
...
...
src/state/multicall/hooks.ts
View file @
9492e737
...
...
@@ -6,7 +6,14 @@ import { useDispatch, useSelector } from 'react-redux'
import
{
useActiveWeb3React
}
from
'
../../hooks
'
import
{
useBlockNumber
}
from
'
../application/hooks
'
import
{
AppDispatch
,
AppState
}
from
'
../index
'
import
{
addMulticallListeners
,
Call
,
removeMulticallListeners
,
parseCallKey
,
toCallKey
}
from
'
./actions
'
import
{
addMulticallListeners
,
Call
,
removeMulticallListeners
,
parseCallKey
,
toCallKey
,
ListenerOptions
}
from
'
./actions
'
export
interface
Result
extends
ReadonlyArray
<
any
>
{
readonly
[
key
:
string
]:
any
...
...
@@ -35,8 +42,13 @@ interface CallResult {
const
INVALID_RESULT
:
CallResult
=
{
valid
:
false
,
blockNumber
:
undefined
,
data
:
undefined
}
// use this options object
export
const
NEVER_RELOAD
:
ListenerOptions
=
{
blocksPerFetch
:
Infinity
}
// the lowest level call for subscribing to contract data
function
useCallsData
(
calls
:
(
Call
|
undefined
)[]):
CallResult
[]
{
function
useCallsData
(
calls
:
(
Call
|
undefined
)[]
,
options
?:
ListenerOptions
):
CallResult
[]
{
const
{
chainId
}
=
useActiveWeb3React
()
const
callResults
=
useSelector
<
AppState
,
AppState
[
'
multicall
'
][
'
callResults
'
]
>
(
state
=>
state
.
multicall
.
callResults
)
const
dispatch
=
useDispatch
<
AppDispatch
>
()
...
...
@@ -60,7 +72,8 @@ function useCallsData(calls: (Call | undefined)[]): CallResult[] {
dispatch
(
addMulticallListeners
({
chainId
,
calls
calls
,
options
})
)
...
...
@@ -68,11 +81,12 @@ function useCallsData(calls: (Call | undefined)[]): CallResult[] {
dispatch
(
removeMulticallListeners
({
chainId
,
calls
calls
,
options
})
)
}
},
[
chainId
,
dispatch
,
serializedCallKeys
])
},
[
chainId
,
dispatch
,
options
,
serializedCallKeys
])
return
useMemo
(
()
=>
...
...
@@ -130,7 +144,8 @@ function toCallState(
export
function
useSingleContractMultipleData
(
contract
:
Contract
|
null
|
undefined
,
methodName
:
string
,
callInputs
:
OptionalMethodInputs
[]
callInputs
:
OptionalMethodInputs
[],
options
?:
ListenerOptions
):
CallState
[]
{
const
fragment
=
useMemo
(()
=>
contract
?.
interface
?.
getFunction
(
methodName
),
[
contract
,
methodName
])
...
...
@@ -147,7 +162,7 @@ export function useSingleContractMultipleData(
[
callInputs
,
contract
,
fragment
]
)
const
results
=
useCallsData
(
calls
)
const
results
=
useCallsData
(
calls
,
options
)
const
latestBlockNumber
=
useBlockNumber
()
...
...
@@ -160,7 +175,8 @@ export function useMultipleContractSingleData(
addresses
:
(
string
|
undefined
)[],
contractInterface
:
Interface
,
methodName
:
string
,
callInputs
?:
OptionalMethodInputs
callInputs
?:
OptionalMethodInputs
,
options
?:
ListenerOptions
):
CallState
[]
{
const
fragment
=
useMemo
(()
=>
contractInterface
.
getFunction
(
methodName
),
[
contractInterface
,
methodName
])
const
callData
:
string
|
undefined
=
useMemo
(
...
...
@@ -186,7 +202,7 @@ export function useMultipleContractSingleData(
[
addresses
,
callData
,
fragment
]
)
const
results
=
useCallsData
(
calls
)
const
results
=
useCallsData
(
calls
,
options
)
const
latestBlockNumber
=
useBlockNumber
()
...
...
@@ -198,7 +214,8 @@ export function useMultipleContractSingleData(
export
function
useSingleCallResult
(
contract
:
Contract
|
null
|
undefined
,
methodName
:
string
,
inputs
?:
OptionalMethodInputs
inputs
?:
OptionalMethodInputs
,
options
?:
ListenerOptions
):
CallState
{
const
fragment
=
useMemo
(()
=>
contract
?.
interface
?.
getFunction
(
methodName
),
[
contract
,
methodName
])
...
...
@@ -213,7 +230,7 @@ export function useSingleCallResult(
:
[]
},
[
contract
,
fragment
,
inputs
])
const
result
=
useCallsData
(
calls
)[
0
]
const
result
=
useCallsData
(
calls
,
options
)[
0
]
const
latestBlockNumber
=
useBlockNumber
()
return
useMemo
(()
=>
{
...
...
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