Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/pages/Dao/components/token/CreateLP.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<string, Token> = { [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;
};

Expand Down Expand Up @@ -141,7 +149,7 @@ const TokenCreateLP: React.FC<TokenConfigComponentsProps> = ({
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;
Expand Down Expand Up @@ -296,7 +304,7 @@ const TokenCreateLP: React.FC<TokenConfigComponentsProps> = ({
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;
Expand Down
27 changes: 24 additions & 3 deletions src/pages/Dao/hooks/useUniswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -58,6 +62,7 @@ export enum PoolState {
INVALID,
}

// XXX may be not use
export function constructSameAddressMap<T extends string>(
address: T,
additionalNetworks: SupportedChainId[] = [],
Expand All @@ -71,6 +76,7 @@ export function constructSameAddressMap<T extends string>(
}, {});
}

// XXX may be not use
export const MULTICALL_ADDRESS: AddressMap = {
...constructSameAddressMap('0x1F98415757620B543A52E61c46B32eB19261F984', [
SupportedChainId.OPTIMISTIC_KOVAN,
Expand All @@ -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,
Expand Down Expand Up @@ -117,6 +124,20 @@ export const WETH9_EXTENDED: Record<number, Token> = {
'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<T extends Currency>(
Expand Down Expand Up @@ -319,9 +340,9 @@ export function useUniswap(
priceUpper: Price<Token, Token> | undefined;
tickLower: number | undefined;
tickUpper: number | undefined;
getNoQuoteTokenPrice: (
currentTick: any,
) => { [bound in Bound]?: Price<Token, Token> | undefined };
getNoQuoteTokenPrice: (currentTick: any) => {
[bound in Bound]?: Price<Token, Token> | undefined;
};
getNoQuoteTokenTick: (currentTick: any) => { [bound in Bound]?: number | undefined };
} {
const {
Expand Down
4 changes: 2 additions & 2 deletions src/services/ethereum-connect/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
33 changes: 26 additions & 7 deletions src/services/ethereum-connect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/services/ethereum-connect/token.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 7 additions & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ export const EthereumNetwork = {
'0x4': 'rinkeby',
'0x5': 'goerli',
'0x2a': 'kovan',
'0x89': 'matic',
'0x13881': 'maticmum',
};

export const EthereumNetworkById = {
Expand All @@ -252,6 +254,8 @@ export const EthereumNetworkById = {
4: 'rinkeby',
5: 'goerli',
42: 'kovan',
137: 'matic',
80001: 'maticmum',
};

export const EthereumChainId = {
Expand All @@ -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],
});