diff --git a/src/pages/Dao/components/token/CreateLP.tsx b/src/pages/Dao/components/token/CreateLP.tsx index c3f4843..aab7e03 100644 --- a/src/pages/Dao/components/token/CreateLP.tsx +++ b/src/pages/Dao/components/token/CreateLP.tsx @@ -21,7 +21,7 @@ import { ERC20Connect } from '@/services/ethereum-connect/erc20'; import styles from './index.less'; import GlobalModal from '@/components/Modal'; import type { Currency } from '@uniswap/sdk-core'; -import { CurrencyAmount, Token, WETH9 } from '@uniswap/sdk-core'; +import { CurrencyAmount, Token } from '@uniswap/sdk-core'; import { Bound, currencyId, @@ -66,14 +66,22 @@ const getCoinGecko = async (network: string) => { const compoundTokenList: TokenToSelects = await request( 'https://raw.githubusercontent.com/compound-finance/token-list/master/compound.tokenlist.json', ); + // const uniswapLabsList: TokenToSelects = await request( + // 'https://tokens.uniswap.org/', + // ); const chainId = EthereumChainId[network]; - const weth9 = WETH9[chainId]; + const weth9 = WETH9_EXTENDED[chainId]; const quoteTokens: Record = { [weth9.address]: weth9 }; compoundTokenList.tokens.forEach((t) => { if (t.chainId === chainId) { quoteTokens[t.address] = new Token(t.chainId, t.address, t.decimals, t.symbol, t.name); } }); + // uniswapLabsList.tokens.forEach((t) => { + // if (t.chainId === chainId) { + // quoteTokens[t.address] = new Token(t.chainId, t.address, t.decimals, t.symbol, t.name); + // } + // }); return quoteTokens; }; @@ -141,7 +149,7 @@ const TokenCreateLP: React.FC = ({ const currencyIdNew = currencyId(quoteCurrency); if ( currencyIdNew === 'ETH' || - quoteCurrency.wrapped.address === WETH9[EthereumChainId[network]].address + quoteCurrency.wrapped.address === WETH9_EXTENDED[EthereumChainId[network]].address ) { library?.getBalance(account).then((ethBalance: BigNumber) => { const amount = ethBalance ? JSBI.BigInt(ethBalance.toString()) : undefined; @@ -296,7 +304,7 @@ const TokenCreateLP: React.FC = ({ if (!quoteCurrency || !account || !tokenAddress) return; if ( quoteCurrency.isNative || - quoteCurrency.wrapped.address === WETH9[EthereumChainId[network]].address + quoteCurrency.wrapped.address === WETH9_EXTENDED[EthereumChainId[network]].address ) { setApprovedQuoteToken(true); return; diff --git a/src/pages/Dao/hooks/useUniswap.ts b/src/pages/Dao/hooks/useUniswap.ts index e7fb351..e936462 100644 --- a/src/pages/Dao/hooks/useUniswap.ts +++ b/src/pages/Dao/hooks/useUniswap.ts @@ -27,12 +27,16 @@ export enum SupportedChainId { GOERLI = 5, KOVAN = 42, + POLYGON = 137, + MUMBAI = 80001, + ARBITRUM_ONE = 42161, ARBITRUM_RINKEBY = 421611, OPTIMISM = 10, OPTIMISTIC_KOVAN = 69, } +// XXX may be not use export const L1_CHAIN_IDS = [ SupportedChainId.MAINNET, SupportedChainId.ROPSTEN, @@ -58,6 +62,7 @@ export enum PoolState { INVALID, } +// XXX may be not use export function constructSameAddressMap( address: T, additionalNetworks: SupportedChainId[] = [], @@ -71,6 +76,7 @@ export function constructSameAddressMap( }, {}); } +// XXX may be not use export const MULTICALL_ADDRESS: AddressMap = { ...constructSameAddressMap('0x1F98415757620B543A52E61c46B32eB19261F984', [ SupportedChainId.OPTIMISTIC_KOVAN, @@ -80,6 +86,7 @@ export const MULTICALL_ADDRESS: AddressMap = { [SupportedChainId.ARBITRUM_RINKEBY]: '0xa501c031958F579dB7676fF1CE78AD305794d579', }; +// XXX may be not use export const V3_CORE_FACTORY_ADDRESSES: AddressMap = constructSameAddressMap(V3_FACTORY_ADDRESS, [ SupportedChainId.OPTIMISM, SupportedChainId.OPTIMISTIC_KOVAN, @@ -117,6 +124,20 @@ export const WETH9_EXTENDED: Record = { 'WETH', 'Wrapped Ether', ), + [SupportedChainId.POLYGON]: new Token( + SupportedChainId.POLYGON, + '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270', + 18, + 'WMATIC', + 'Wrapped Matic', + ), + [SupportedChainId.MUMBAI]: new Token( + SupportedChainId.MUMBAI, + '0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889', + 18, + 'WMATIC', + 'Wrapped Matic', + ), }; export function tryParseAmount( @@ -319,9 +340,9 @@ export function useUniswap( priceUpper: Price | undefined; tickLower: number | undefined; tickUpper: number | undefined; - getNoQuoteTokenPrice: ( - currentTick: any, - ) => { [bound in Bound]?: Price | undefined }; + getNoQuoteTokenPrice: (currentTick: any) => { + [bound in Bound]?: Price | undefined; + }; getNoQuoteTokenTick: (currentTick: any) => { [bound in Bound]?: number | undefined }; } { const { diff --git a/src/services/ethereum-connect/factory.ts b/src/services/ethereum-connect/factory.ts index c6ced57..091b730 100644 --- a/src/services/ethereum-connect/factory.ts +++ b/src/services/ethereum-connect/factory.ts @@ -6,8 +6,8 @@ import { ethers } from 'ethers'; export class DAOFactoryConnect extends BaseEthereumConnect { constructor(network: string, metamaskProvider: any) { super(network, metamaskProvider); - this.contract = DAOFactoryContract(this.provider); - this.actionContract = DAOFactoryContract(this.metamaskProvider); + this.contract = DAOFactoryContract(network, this.provider); + this.actionContract = DAOFactoryContract(network, this.metamaskProvider); } async check() { diff --git a/src/services/ethereum-connect/index.ts b/src/services/ethereum-connect/index.ts index 8df6ed7..af03dbf 100644 --- a/src/services/ethereum-connect/index.ts +++ b/src/services/ethereum-connect/index.ts @@ -13,7 +13,18 @@ import { EthereumChainId } from '@/utils/utils'; import JSBI from 'jsbi'; import { ADDRESS_ZERO } from '@uniswap/v3-sdk'; +export const DAOFactoryAddressInfo = { + homestead: '0x7b728FD84995fAC43A500Ae144A1e121916E5c07', + ropsten: '0x7b728FD84995fAC43A500Ae144A1e121916E5c07', + rinkeby: '0x7b728FD84995fAC43A500Ae144A1e121916E5c07', + goerli: '0x7b728FD84995fAC43A500Ae144A1e121916E5c07', + kovan: '0x7b728FD84995fAC43A500Ae144A1e121916E5c07', + matic: '0x0000000000000000000000000000000000000000', + maticmum: '0xac6faA8065c6aC2FbF42ac21553F64c00181BD40', +}; + export const DAOFactoryAddress = '0x7b728FD84995fAC43A500Ae144A1e121916E5c07'; + export const DAOFactoryVersion = JSBI.BigInt(1); export const DAOStakingAddress = ADDRESS_ZERO; export const ZeroAddress = ADDRESS_ZERO; @@ -22,11 +33,15 @@ export const UniswapPoolAddress = '0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8'; export const UniswapV3PositionsAddress = '0xC36442b4a4522E871399CD717aBDD847Ab11FE88'; export function getProvider(network: string) { - return ethers.getDefaultProvider(getNetwork(network), { - infura: REACT_APP_ICPDAO_ETHEREUM_INFURA_KEY, - alchemy: REACT_APP_ICPDAO_ETHEREUM_ALCHEMY_KEY, - etherscan: REACT_APP_ICPDAO_ETHEREUM_ETHERSCAN_KEY, - }); + // return ethers.getDefaultProvider(getNetwork(network), { + // infura: REACT_APP_ICPDAO_ETHEREUM_INFURA_KEY, + // alchemy: REACT_APP_ICPDAO_ETHEREUM_ALCHEMY_KEY, + // etherscan: REACT_APP_ICPDAO_ETHEREUM_ETHERSCAN_KEY, + // }); + return new ethers.providers.AlchemyProvider( + getNetwork(network), + REACT_APP_ICPDAO_ETHEREUM_ALCHEMY_KEY, + ); } export function getEtherscanProvider(network: string) { @@ -36,8 +51,12 @@ export function getEtherscanProvider(network: string) { ); } -export function DAOFactoryContract(provider: any) { - return new ethers.Contract(DAOFactoryAddress, DAOFactoryABI, provider); +export function DAOFactoryContract(network: string, provider: any) { + let address = DAOFactoryAddress; + if (network) { + address = DAOFactoryAddressInfo[network]; + } + return new ethers.Contract(address, DAOFactoryABI, provider); } export function DAOStakingContract(provider: any) { diff --git a/src/services/ethereum-connect/token.ts b/src/services/ethereum-connect/token.ts index 5ea0beb..1e9361f 100644 --- a/src/services/ethereum-connect/token.ts +++ b/src/services/ethereum-connect/token.ts @@ -1,7 +1,7 @@ import { DAOTokenContract } from './index'; import { ERC20Connect } from '@/services/ethereum-connect/erc20'; import type { ETH_CONNECT } from '@/services/ethereum-connect/typings'; -import { WETH9 } from '@uniswap/sdk-core'; +import { WETH9_EXTENDED } from '@/pages/Dao/hooks/useUniswap'; export class DAOTokenConnect extends ERC20Connect { constructor(tokenAddress: string, network: string, metamaskProvider: any) { @@ -31,7 +31,7 @@ export class DAOTokenConnect extends ERC20Connect { const contractWithSigner = this.actionContract.connect(signer); console.log({ body }); let value = '0'; - if (WETH9[this.chainId].address === body.quoteTokenAddress) { + if (WETH9_EXTENDED[this.chainId].address === body.quoteTokenAddress) { value = body.quoteTokenAmount; } return await contractWithSigner.createLPPoolOrLinkLPPool( diff --git a/src/utils/utils.ts b/src/utils/utils.ts index a35954d..af57263 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -244,6 +244,8 @@ export const EthereumNetwork = { '0x4': 'rinkeby', '0x5': 'goerli', '0x2a': 'kovan', + '0x89': 'matic', + '0x13881': 'maticmum', }; export const EthereumNetworkById = { @@ -252,6 +254,8 @@ export const EthereumNetworkById = { 4: 'rinkeby', 5: 'goerli', 42: 'kovan', + 137: 'matic', + 80001: 'maticmum', }; export const EthereumChainId = { @@ -260,8 +264,10 @@ export const EthereumChainId = { rinkeby: 4, goerli: 5, kovan: 42, + matic: 137, + maticmum: 80001, }; export const Injected = new InjectedConnector({ - supportedChainIds: [1, 3, 4, 5, 42], + supportedChainIds: [1, 3, 4, 5, 42, 137, 80001], });