Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[COW-SDK] - replace SupportedChainId and change xDai > Gnosis Chain #561

Merged
merged 4 commits into from
May 27, 2022
Merged
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@babel/preset-env": "^7.16.11",
"@babel/preset-react": "^7.16.7",
"@babel/preset-typescript": "^7.16.7",
"@cowprotocol/cow-sdk": "0.0.11",
"@craco/craco": "^5.7.0",
"@graphql-codegen/cli": "1.21.5",
"@graphql-codegen/typescript": "1.22.3",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Toggle/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Trans } from '@lingui/macro'
import { WithClassName } from '@src/custom/types'
import { WithClassName } from 'types'
import { darken } from 'polished'
import { ReactNode } from 'react'
import styled from 'styled-components/macro'
Expand Down
2 changes: 1 addition & 1 deletion src/custom/api/coingecko/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function _getCoinGeckoAssetPlatform(chainId: ChainId) {
// https://api.coingecko.com/api/v3/asset_platforms
case ChainId.MAINNET:
return 'ethereum'
case ChainId.XDAI:
case ChainId.GNOSIS_CHAIN:
return 'xdai'
default:
return null
Expand Down
8 changes: 4 additions & 4 deletions src/custom/api/gnosisProtocol/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ function getGnosisProtocolUrl(): Partial<Record<ChainId, string>> {
return {
[ChainId.MAINNET]: process.env.REACT_APP_API_URL_STAGING_MAINNET || 'https://barn.api.cow.fi/mainnet/api',
[ChainId.RINKEBY]: process.env.REACT_APP_API_URL_STAGING_RINKEBY || 'https://barn.api.cow.fi/rinkeby/api',
[ChainId.XDAI]: process.env.REACT_APP_API_URL_STAGING_XDAI || 'https://barn.api.cow.fi/xdai/api',
[ChainId.GNOSIS_CHAIN]: process.env.REACT_APP_API_URL_STAGING_XDAI || 'https://barn.api.cow.fi/xdai/api',
}
}

// Production, staging, ens, ...
return {
[ChainId.MAINNET]: process.env.REACT_APP_API_URL_PROD_MAINNET || 'https://api.cow.fi/mainnet/api',
[ChainId.RINKEBY]: process.env.REACT_APP_API_URL_PROD_RINKEBY || 'https://api.cow.fi/rinkeby/api',
[ChainId.XDAI]: process.env.REACT_APP_API_URL_PROD_XDAI || 'https://api.cow.fi/xdai/api',
[ChainId.GNOSIS_CHAIN]: process.env.REACT_APP_API_URL_PROD_XDAI || 'https://api.cow.fi/xdai/api',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we maybe update the env variable names for consistency or is it fine to leave it as this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, will create an issue to address it post merge

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}

Expand All @@ -68,7 +68,7 @@ function getPriceStrategyUrl(): Record<SupportedChainId, string> {
return {
[SupportedChainId.MAINNET]: STRATEGY_URL_BASE + '/strategy-1.json',
[SupportedChainId.RINKEBY]: STRATEGY_URL_BASE + '/strategy-4.json',
[SupportedChainId.XDAI]: STRATEGY_URL_BASE + '/strategy-100.json',
[SupportedChainId.GNOSIS_CHAIN]: STRATEGY_URL_BASE + '/strategy-100.json',
}
}

Expand Down Expand Up @@ -552,7 +552,7 @@ export async function getGasPrices(chainId: ChainId = DEFAULT_NETWORK_FOR_LISTS)
const response = await fetch(GAS_FEE_ENDPOINTS[chainId])
const json = await response.json()

if (chainId === SupportedChainId.XDAI) {
if (chainId === SupportedChainId.GNOSIS_CHAIN) {
// Different endpoint for GChain with a different format. Need to transform it
return _transformGChainGasPrices(json)
}
Expand Down
6 changes: 3 additions & 3 deletions src/custom/api/gnosisSafe/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import SafeServiceClient, { SafeInfoResponse, SafeMultisigTransactionResponse } from '@gnosis.pm/safe-service-client'
import { registerOnWindow } from 'utils/misc'
import { ChainId } from '@uniswap/sdk'
import { SupportedChainId as ChainId } from 'constants/chains'

const SAFE_TRANSACTION_SERVICE_URL: Partial<Record<number, string>> = {
[ChainId.MAINNET]: 'https://safe-transaction.gnosis.io',
[ChainId.RINKEBY]: 'https://safe-transaction.rinkeby.gnosis.io',
[ChainId.XDAI]: 'https://safe-transaction.xdai.gnosis.io',
[ChainId.GNOSIS_CHAIN]: 'https://safe-transaction.xdai.gnosis.io',
}

const SAFE_BASE_URL = 'https://gnosis-safe.io'
const CHAIN_SHORT_NAME: Partial<Record<number, string>> = {
[ChainId.MAINNET]: 'eth', // https://github.com/ethereum-lists/chains/blob/master/_data/chains/eip155-1.json
[ChainId.RINKEBY]: 'rin', // https://github.com/ethereum-lists/chains/blob/master/_data/chains/eip155-4.json
[ChainId.XDAI]: 'xdai', // https://github.com/ethereum-lists/chains/blob/master/_data/chains/eip155-100.json
[ChainId.GNOSIS_CHAIN]: 'xdai', // https://github.com/ethereum-lists/chains/blob/master/_data/chains/eip155-100.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, but this is only internal.
While I do agree with you and this is mildly annoying, I'm fine to have the long version

}

const SAFE_TRANSACTION_SERVICE_CACHE: Partial<Record<number, SafeServiceClient | null>> = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ const ExplorerLabel = ({ chainId }: { chainId: SupportedChainId }) => {
case SupportedChainId.POLYGON:
case SupportedChainId.POLYGON_MUMBAI:
return <Trans>Polygonscan</Trans> */
case SupportedChainId.XDAI:
case SupportedChainId.GNOSIS_CHAIN:
return <Trans>Blockscout</Trans>
default:
return <Trans>Etherscan</Trans>
Expand Down Expand Up @@ -433,7 +433,7 @@ export default function NetworkSelector() {
</FlyoutHeader>
<Row onSelectChain={handleChainSwitch} targetChain={SupportedChainId.MAINNET} />
<Row onSelectChain={handleChainSwitch} targetChain={SupportedChainId.RINKEBY} />
<Row onSelectChain={handleChainSwitch} targetChain={SupportedChainId.XDAI} />
<Row onSelectChain={handleChainSwitch} targetChain={SupportedChainId.GNOSIS_CHAIN} />
</FlyoutMenuContents>
</FlyoutMenu>
)}
Expand Down
4 changes: 2 additions & 2 deletions src/custom/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ export const NETWORK_LABELS: { [chainId in ChainId]?: string } = {
// [ChainId.ROPSTEN]: 'Ropsten',
// [ChainId.GOERLI]: 'Görli',
// [ChainId.KOVAN]: 'Kovan',
[ChainId.XDAI]: 'Gnosis Chain',
[ChainId.GNOSIS_CHAIN]: 'Gnosis Chain',
}

const CHAIN_CURRENCY_LABELS: { [chainId in ChainId]?: string } = {
[ChainId.XDAI]: 'xDAI',
[ChainId.GNOSIS_CHAIN]: 'xDAI',
}

export interface LinkType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const SHOULD_SHOW_ALERT = {
[SupportedChainId.ARBITRUM_RINKEBY]: true,
[SupportedChainId.POLYGON]: true,
[SupportedChainId.POLYGON_MUMBAI]: true, */
[SupportedChainId.XDAI]: true,
[SupportedChainId.GNOSIS_CHAIN]: true,
}

type NetworkAlertChains = keyof typeof SHOULD_SHOW_ALERT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ConfirmationModalContent as ConfirmationModalContentMod } from './Trans
import { ColumnCenter } from 'components/Column'
import { getStatusIcon } from 'components/AccountDetails'
import { shortenAddress } from 'utils'
import { getChainCurrencySymbols } from 'utils/xdai/hack'
import { getChainCurrencySymbols } from 'utils/gnosis_chain/hack'

const Wrapper = styled.div`
width: 100%;
Expand Down
2 changes: 1 addition & 1 deletion src/custom/components/Web3Status/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AbstractConnector } from '@web3-react/abstract-connector'
import { getStatusIcon } from 'components/AccountDetails'
import useRecentActivity, { TransactionAndOrder } from 'hooks/useRecentActivity'
import { useWalletInfo } from 'hooks/useWalletInfo'
import { OrderStatus } from '@src/custom/state/orders/actions'
import { OrderStatus } from 'state/orders/actions'
import { STORAGE_KEY_LAST_PROVIDER } from 'constants/index'

export const Wrapper = styled.div`
Expand Down
2 changes: 1 addition & 1 deletion src/custom/constants/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export * from '@src/constants/addresses'

export const MULTICALL_ADDRESS: AddressMap = {
...MULTICALL2_ADDRESSES_UNI,
[SupportedChainId.XDAI]: '0x0f41c16b8ad27c11f181eca85f0941868c1297af',
[SupportedChainId.GNOSIS_CHAIN]: '0x0f41c16b8ad27c11f181eca85f0941868c1297af',
}
2 changes: 1 addition & 1 deletion src/custom/constants/chainInfo/chainInfoMod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export const CHAIN_INFO: ChainInfoMap = {
logoUrl: polygonMaticLogo,
nativeCurrency: { name: 'Polygon Mumbai Matic', symbol: 'mMATIC', decimals: 18 },
},*/
[SupportedChainId.XDAI]: {
[SupportedChainId.GNOSIS_CHAIN]: {
networkType: NetworkType.L1,
docs: 'https://docs.gnosischain.com/',
bridge: 'https://omni.gnosischain.com/bridge',
Expand Down
21 changes: 9 additions & 12 deletions src/custom/constants/chains/chainsMod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,28 @@
*/

import { CHAIN_IDS_TO_NAMES as UNI_CHAIN_IDS_TO_NAMES } from '@src/constants/chains'
import { SupportedChainId } from '@cowprotocol/cow-sdk'

export * from '@src/constants/chains'
export { SupportedChainId } from '@cowprotocol/cow-sdk'

export enum SupportedChainId {
/* export enum SupportedChainId {
MAINNET = 1,
// ROPSTEN = 3,
ROPSTEN = 3,
RINKEBY = 4,
/* GOERLI = 5,
GOERLI = 5,
KOVAN = 42,

ARBITRUM_ONE = 42161,
ARBITRUM_RINKEBY = 421611,

OPTIMISM = 10,
OPTIMISTIC_KOVAN = 69,

POLYGON = 137,
POLYGON_MUMBAI = 80001, */

XDAI = 100,
}
POLYGON_MUMBAI = 80001,
}*/

export const CHAIN_IDS_TO_NAMES = {
...UNI_CHAIN_IDS_TO_NAMES,
[SupportedChainId.XDAI]: 'gnosis_chain',
[SupportedChainId.GNOSIS_CHAIN]: 'gnosis_chain',
/* [SupportedChainId.MAINNET]: 'mainnet',
[SupportedChainId.ROPSTEN]: 'ropsten',
[SupportedChainId.RINKEBY]: 'rinkeby',
Expand Down Expand Up @@ -61,7 +58,7 @@ export const L1_CHAIN_IDS = [
SupportedChainId.KOVAN,
SupportedChainId.POLYGON,
SupportedChainId.POLYGON_MUMBAI, */
SupportedChainId.XDAI,
SupportedChainId.GNOSIS_CHAIN,
] as const

export type SupportedL1ChainId = typeof L1_CHAIN_IDS[number]
Expand Down
12 changes: 6 additions & 6 deletions src/custom/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ export const UNSUPPORTED_WC_WALLETS = new Set(['DeFi Wallet', 'WallETH'])
export const GP_SETTLEMENT_CONTRACT_ADDRESS: Partial<Record<number, string>> = {
[ChainId.MAINNET]: GPv2Settlement[ChainId.MAINNET].address,
[ChainId.RINKEBY]: GPv2Settlement[ChainId.RINKEBY].address,
[ChainId.XDAI]: GPv2Settlement[ChainId.XDAI].address,
[ChainId.GNOSIS_CHAIN]: GPv2Settlement[ChainId.GNOSIS_CHAIN].address,
}

export const GP_VAULT_RELAYER: Partial<Record<number, string>> = {
[ChainId.MAINNET]: GPv2VaultRelayer[ChainId.MAINNET].address,
[ChainId.RINKEBY]: GPv2VaultRelayer[ChainId.RINKEBY].address,
[ChainId.XDAI]: GPv2VaultRelayer[ChainId.XDAI].address,
[ChainId.GNOSIS_CHAIN]: GPv2VaultRelayer[ChainId.GNOSIS_CHAIN].address,
}

export const V_COW_CONTRACT_ADDRESS: Record<number, string> = {
[ChainId.MAINNET]: '0xd057b63f5e69cf1b929b356b579cba08d7688048',
[ChainId.XDAI]: '0xc20C9C13E853fc64d054b73fF21d3636B2d97eaB',
[ChainId.GNOSIS_CHAIN]: '0xc20C9C13E853fc64d054b73fF21d3636B2d97eaB',
[ChainId.RINKEBY]: '0x9386177e95A853070076Df2403b9D547D653126D',
}

export const COW_CONTRACT_ADDRESS: Record<number, string> = {
[ChainId.MAINNET]: '0xDEf1CA1fb7FBcDC777520aa7f396b4E015F497aB',
[ChainId.XDAI]: '0x177127622c4A00F3d409B75571e12cB3c8973d3c',
[ChainId.GNOSIS_CHAIN]: '0x177127622c4A00F3d409B75571e12cB3c8973d3c',
[ChainId.RINKEBY]: '0xbdf1e19f8c78A77fb741b44EbA5e4c0C8DBAeF91',
}

Expand All @@ -77,7 +77,7 @@ export const NATIVE_CURRENCY_BUY_TOKEN: { [chainId in ChainId | number]: Token }
// [ChainId.ROPSTEN]: new Token(ChainId.ROPSTEN, NATIVE_CURRENCY_BUY_ADDRESS, 18, 'ETH', 'Ether'),
// [ChainId.GOERLI]: new Token(ChainId.GOERLI, NATIVE_CURRENCY_BUY_ADDRESS, 18, 'ETH', 'Ether'),
// [ChainId.KOVAN]: new Token(ChainId.KOVAN, NATIVE_CURRENCY_BUY_ADDRESS, 18, 'ETH', 'Ether'),
[ChainId.XDAI]: new Token(ChainId.XDAI, NATIVE_CURRENCY_BUY_ADDRESS, 18, 'xDAI', 'xDAI'),
[ChainId.GNOSIS_CHAIN]: new Token(ChainId.GNOSIS_CHAIN, NATIVE_CURRENCY_BUY_ADDRESS, 18, 'xDAI', 'xDAI'),
}

export const ORDER_ID_SHORT_LENGTH = 8
Expand Down Expand Up @@ -122,7 +122,7 @@ export const GAS_FEE_ENDPOINTS = {
// [ChainId.GOERLI]: 'https://safe-relay.goerli.gnosis.io/api/v1/gas-station/',
// no kovan = main
// [ChainId.KOVAN]: 'https://safe-relay.kovan.gnosis.io/api/v1/gas-station/',
[ChainId.XDAI]: 'https://blockscout.com/xdai/mainnet/api/v1/gas-price-oracle',
[ChainId.GNOSIS_CHAIN]: 'https://blockscout.com/xdai/mainnet/api/v1/gas-price-oracle',
}

export const UNSUPPORTED_TOKENS_FAQ_URL = '/faq/trading#what-token-pairs-does-cowswap-allow-to-trade'
Expand Down
8 changes: 4 additions & 4 deletions src/custom/constants/lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const UNSUPPORTED_LIST_URLS: NetworkLists = {
[ChainId.RINKEBY]: [BA_LIST],
// [ChainId.ROPSTEN]: [BA_LIST],
// [ChainId.GOERLI]: [BA_LIST],
[ChainId.XDAI]: [BA_LIST],
[ChainId.GNOSIS_CHAIN]: [BA_LIST],
}

function buildNetworkDefaultLists({ networkLists, chainId }: { chainId: ChainId; networkLists: string[] }) {
Expand Down Expand Up @@ -81,8 +81,8 @@ export const DEFAULT_LIST_OF_LISTS_BY_NETWORK: NetworkLists = {
// chainId: ChainId.GOERLI,
// networkLists: [COMPOUND_LIST],
// }),
[ChainId.XDAI]: buildNetworkDefaultLists({
chainId: ChainId.XDAI,
[ChainId.GNOSIS_CHAIN]: buildNetworkDefaultLists({
chainId: ChainId.GNOSIS_CHAIN,
networkLists: [COW_DAO_LIST, HONEY_SWAP_XDAI],
}),
}
Expand All @@ -93,7 +93,7 @@ export const DEFAULT_ACTIVE_LIST_URLS_BY_NETWORK: NetworkLists = {
// [ChainId.KOVAN]: [GEMINI_LIST],
[ChainId.RINKEBY]: [COW_DAO_LIST, RINKEBY_LIST],
// [ChainId.ROPSTEN]: [GEMINI_LIST],
[ChainId.XDAI]: [COW_DAO_LIST, HONEY_SWAP_XDAI],
[ChainId.GNOSIS_CHAIN]: [COW_DAO_LIST, HONEY_SWAP_XDAI],
// [ChainId.GOERLI]: [GEMINI_LIST],
}

Expand Down
18 changes: 9 additions & 9 deletions src/custom/constants/routing/routingMod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from 'constants/tokens'

// MOD imports
import { USDC_XDAI, WBTC_XDAI, WETH_XDAI } from 'utils/xdai/constants'
import { USDC_GNOSIS_CHAIN, WBTC_GNOSIS_CHAIN, WETH_GNOSIS_CHAIN } from 'utils/gnosis_chain/constants'
import { DAI_RINKEBY, USDC_RINKEBY, USDT_RINKEBY } from 'utils/rinkeby/constants'

/* type ChainTokenList = {
Expand Down Expand Up @@ -151,14 +151,14 @@ export const COMMON_BASES: ChainCurrencyList = {
WRAPPED_NATIVE_CURRENCY[SupportedChainId.POLYGON_MUMBAI],
WETH_POLYGON_MUMBAI,
], */
[SupportedChainId.XDAI]: [
// nativeOnChain(SupportedChainId.XDAI),
USDC_XDAI,
WBTC_XDAI,
COW[SupportedChainId.XDAI],
/*USDT_XDAI,*/ WBTC_XDAI,
WETH_XDAI,
WRAPPED_NATIVE_CURRENCY[SupportedChainId.XDAI],
[SupportedChainId.GNOSIS_CHAIN]: [
// nativeOnChain(SupportedChainId.GNOSIS_CHAIN),
USDC_GNOSIS_CHAIN,
WBTC_GNOSIS_CHAIN,
COW[SupportedChainId.GNOSIS_CHAIN],
/*USDT_GNOSIS_CHAIN,*/ WBTC_GNOSIS_CHAIN,
WETH_GNOSIS_CHAIN,
WRAPPED_NATIVE_CURRENCY[SupportedChainId.GNOSIS_CHAIN],
], // mod
}

Expand Down
Loading