Skip to content

Commit

Permalink
feat: integrate celo (#5052)
Browse files Browse the repository at this point in the history
  • Loading branch information
brymut committed Dec 26, 2021
1 parent b08b37c commit c5cfdf3
Show file tree
Hide file tree
Showing 52 changed files with 399 additions and 132 deletions.
3 changes: 3 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"Burkina",
"CAIP",
"Caicos",
"Celo",
"Checksummed",
"Cunha",
"Cura",
Expand Down Expand Up @@ -261,6 +262,8 @@
"Gorli",
"Gwapj",
"HUSD",
"CUSD",
"CEUR",
"Horiz",
"Huobi",
"MSKA",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface SettingItemProps {
legend: string
value: any
options: option[]
onChange?: (value: any) => void
onChange?: (value: string) => void
}

interface StyledFormControlLabelProps extends FormControlLabelProps {
Expand Down
19 changes: 14 additions & 5 deletions packages/dashboard/src/pages/Labs/components/SwapSettingDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
usePolygonNetworkTradeProvider,
useArbitrumNetworkTradeProvider,
useXDaiNetworkTradeProvider,
useCeloNetworkTradeProvider,
} from '../../Settings/api'

import SettingItem from './SettingItem'
Expand Down Expand Up @@ -47,38 +48,46 @@ export default function SwapSettingDialog({ open, onClose }: SettingDialogProps)

const xDaiOptions = [{ label: 'SushiSwap', value: TradeProvider.SUSHISWAP }]

const celoOptions = [{ label: 'SushiSwap', value: TradeProvider.SUSHISWAP }]

const t = useDashboardI18N()

const items = [
{
legend: t.labs_settings_swap_network({ network: 'ETH' }),
value: useEthereumNetworkTradeProvider(),
options: ethOptions,
onChange: (value: any) => Services.Settings.setEthNetworkTradeProvider(+value),
onChange: (value: string) => Services.Settings.setEthNetworkTradeProvider(Number.parseInt(value, 10)),
},
{
legend: t.labs_settings_swap_network({ network: 'Polygon/Matic' }),
value: usePolygonNetworkTradeProvider(),
options: polygonOptions,
onChange: (value: any) => Services.Settings.setPolygonNetworkTradeProvider(+value),
onChange: (value: string) => Services.Settings.setPolygonNetworkTradeProvider(Number.parseInt(value, 10)),
},
{
legend: t.labs_settings_swap_network({ network: 'BSC' }),
value: useBinanceNetworkTradeProvider(),
options: bscOptions,
onChange: (value: any) => Services.Settings.setBinanceNetworkTradeProvider(+value),
onChange: (value: string) => Services.Settings.setBinanceNetworkTradeProvider(Number.parseInt(value, 10)),
},
{
legend: t.labs_settings_swap_network({ network: 'Arbitrum' }),
value: useArbitrumNetworkTradeProvider(),
options: arbitrumOptions,
onChange: (value: any) => Services.Settings.setArbitrumNetworkTradeProvider(+value),
onChange: (value: string) => Services.Settings.setArbitrumNetworkTradeProvider(Number.parseInt(value, 10)),
},
{
legend: t.labs_settings_swap_network({ network: 'xDai' }),
value: useXDaiNetworkTradeProvider(),
options: xDaiOptions,
onChange: (value: any) => Services.Settings.setxDaiNetworkTradeProvider(+value),
onChange: (value: string) => Services.Settings.setxDaiNetworkTradeProvider(Number.parseInt(value, 10)),
},
{
legend: t.labs_settings_swap_network({ network: 'Celo' }),
value: useCeloNetworkTradeProvider(),
options: celoOptions,
onChange: (value: string) => Services.Settings.setCeloNetworkTradeProvider(Number.parseInt(value, 10)),
},
]

Expand Down
5 changes: 5 additions & 0 deletions packages/dashboard/src/pages/Settings/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export const [useXDaiNetworkTradeProvider] = createGlobalState(
Messages.events.xdaiNetworkTradeProviderSettings.on,
)

export const [useCeloNetworkTradeProvider] = createGlobalState(
Services.Settings.getCeloNetworkTradeProvider,
Messages.events.celoNetworkTradeProviderSettings.on,
)

const BASE_RUL = 'https://vaalh28dbi.execute-api.ap-east-1.amazonaws.com/api'

interface BackupBaseRequest {
Expand Down
1 change: 1 addition & 0 deletions packages/mask/shared/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const Flags = {
arbitrum_enabled: true,
xdai_enabled: true,
flow_enabled: true,
celo_enabled: true,
nft_airdrop_enabled: false,

//#region Functionality missing / broken
Expand Down
4 changes: 2 additions & 2 deletions packages/mask/src/components/shared/ApplicationBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export function ApplicationBoard({ secondEntries, secondEntryChainTabs }: MaskAp
]),
createEntry('dHEDGE', new URL('./assets/dHEDGE.png', import.meta.url).toString(), () => {}),
],
[ChainId.Mainnet, ChainId.BSC, ChainId.Matic, ChainId.Arbitrum, ChainId.xDai],
[ChainId.Mainnet, ChainId.BSC, ChainId.Matic, ChainId.Arbitrum, ChainId.xDai, ChainId.Celo],
),
undefined,
true,
Expand All @@ -301,7 +301,7 @@ export function ApplicationBoard({ secondEntries, secondEntryChainTabs }: MaskAp
() => {},
),
],
[ChainId.Mainnet, ChainId.BSC, ChainId.Matic, ChainId.Arbitrum, ChainId.xDai],
[ChainId.Mainnet, ChainId.BSC, ChainId.Matic, ChainId.Arbitrum, ChainId.xDai, ChainId.Celo],
),
undefined,
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
polygonNetworkTradeProviderSettings,
arbitrumNetworkTradeProviderSettings,
xdaiNetworkTradeProviderSettings,
celoNetworkTradeProviderSettings,
} from '../../plugins/Trader/settings'
import { queryMyPersonas } from './IdentityService'
import {
Expand Down Expand Up @@ -73,6 +74,8 @@ export const [getArbitrumNetworkTradeProvider, setArbitrumNetworkTradeProvider]
)
export const [getxDaiNetworkTradeProvider, setxDaiNetworkTradeProvider] = create(xdaiNetworkTradeProviderSettings)

export const [getCeloNetworkTradeProvider, setCeloNetworkTradeProvider] = create(celoNetworkTradeProviderSettings)

export const [getCurrentSelectedWalletProvider, setCurrentSelectedWalletProvider] = create(currentProviderSettings)

export const [getCurrentSelectedWalletNetwork, setCurrentSelectedWalletNetwork] = create(currentNetworkSettings)
Expand Down
Binary file added packages/mask/src/plugins/EVM/assets/celo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions packages/mask/src/plugins/EVM/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ export const PLUGIN_NETWORKS: Web3Plugin.NetworkDescriptor[] = [
iconColor: 'rgb(73, 169, 166)',
isMainnet: true,
},
{
ID: `${PLUGIN_ID}_celo`,
networkSupporterPluginID: PLUGIN_ID,
chainId: ChainId.Celo,
type: NetworkType.Celo,
name: 'Celo',
icon: new URL('./assets/celo.png', import.meta.url),
iconColor: 'rgb(53, 208, 127)',
isMainnet: true,
},
]
export const PLUGIN_PROVIDERS: Web3Plugin.ProviderDescriptor[] = [
{
Expand Down
2 changes: 2 additions & 0 deletions packages/mask/src/plugins/Trader/apis/trader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export async function getAvailableTraderProviders(chainId: ChainId) {
return [TradeProvider.UNISWAP_V3]
case NetworkType.xDai:
return [TradeProvider.SUSHISWAP]
case NetworkType.Celo:
return [TradeProvider.SUSHISWAP]
default:
safeUnreachable(networkType)
return []
Expand Down
3 changes: 3 additions & 0 deletions packages/mask/src/plugins/Trader/apis/trending/hotfix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,23 @@ const NETWORK_ID_MAP: Record<DataProvider, Record<NetworkType, string>> = {
[NetworkType.Polygon]: 'polygon-pos',
[NetworkType.Arbitrum]: 'arbitrum-one',
[NetworkType.xDai]: 'xdai',
[NetworkType.Celo]: 'celo',
},
[DataProvider.COIN_MARKET_CAP]: {
[NetworkType.Ethereum]: '1027',
[NetworkType.Binance]: '1839',
[NetworkType.Polygon]: '3890',
[NetworkType.Arbitrum]: '11841',
[NetworkType.xDai]: '5601',
[NetworkType.Celo]: '0',
},
[DataProvider.UNISWAP_INFO]: {
[NetworkType.Ethereum]: '',
[NetworkType.Binance]: '',
[NetworkType.Polygon]: '',
[NetworkType.Arbitrum]: '',
[NetworkType.xDai]: '',
[NetworkType.Celo]: '',
},
}

Expand Down
1 change: 1 addition & 0 deletions packages/mask/src/plugins/Trader/constants/0x.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const ZRX_BASE_URL: Record<NetworkType, string> = {
[NetworkType.Polygon]: 'https://polygon.api.0x.org/',
[NetworkType.Arbitrum]: 'https://arbitrum.api.0x.org/',
[NetworkType.xDai]: 'https://xdai.api.0x.org/',
[NetworkType.Celo]: 'https://celo.api.0x.org/',
}

export const ZRX_AFFILIATE_ADDRESS = '0x934B510D4C9103E6a87AEf13b816fb080286D649'
1 change: 1 addition & 0 deletions packages/mask/src/plugins/Trader/constants/dodo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export const networkNames: Record<NetworkType, string> = {
[NetworkType.Polygon]: 'matic',
[NetworkType.Arbitrum]: 'arbitrum',
[NetworkType.xDai]: 'xdai',
[NetworkType.Celo]: 'celo',
}
20 changes: 19 additions & 1 deletion packages/mask/src/plugins/Trader/constants/sushiswap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
import { ChainId } from '@masknet/web3-shared-evm'
import { DAI, MSKA, MSKB, MSKC, RUNE, USDC, USDT, WBTC, WNATIVE, WNATIVE_ONLY, NFTX, STETH, BUSD, BTCB } from './trader'
import {
DAI,
MSKA,
MSKB,
MSKC,
RUNE,
USDC,
USDT,
WBTC,
WNATIVE,
WNATIVE_ONLY,
NFTX,
STETH,
BUSD,
BTCB,
CUSD,
CEUR,
} from './trader'
import type { ERC20AgainstToken, ERC20TokenCustomizedBase } from './types'

/**
Expand All @@ -15,4 +32,5 @@ export const SUSHISWAP_BASE_AGAINST_TOKENS: ERC20AgainstToken = {
[ChainId.Matic]: [WNATIVE, USDC, WBTC, DAI, USDT].map((x) => x[ChainId.Matic]),
[ChainId.BSC]: [WNATIVE, DAI, BUSD, USDC, USDT, BTCB].map((x) => x[ChainId.BSC]),
[ChainId.xDai]: [WNATIVE, USDC, USDT, WBTC].map((x) => x[ChainId.xDai]),
[ChainId.Celo]: [WNATIVE, CUSD, CEUR].map((x) => x[ChainId.Celo]),
}
3 changes: 3 additions & 0 deletions packages/mask/src/plugins/Trader/constants/trader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export const CAKE = createERC20Tokens('CAKE_ADDRESS', 'PancakeSwap Token', 'CAKE
export const maUSDC = createERC20Tokens('maUSDC_ADDRESS', 'Matic Aave interest bearing USDC', 'maUSDC', 6)
export const NFTX = createERC20Tokens('NFTX_ADDRESS', 'NFTX', 'NFTX', 18)
export const STETH = createERC20Tokens('stETH_ADDRESS', 'stakedETH', 'stETH', 18)
export const CUSD = createERC20Tokens('cUSD_ADDRESS', 'Celo Dollar', 'cUSD', 18)
export const CEUR = createERC20Tokens('cEUR_ADDRESS', 'Celo Euro', 'cEUR', 18)

export const WNATIVE = createERC20Tokens(
'WNATIVE_ADDRESS',
Expand All @@ -61,6 +63,7 @@ export const WNATIVE_ONLY: ERC20AgainstToken = {
[ChainId.Arbitrum]: [WNATIVE[ChainId.Arbitrum]],
[ChainId.Arbitrum_Rinkeby]: [WNATIVE[ChainId.Arbitrum_Rinkeby]],
[ChainId.xDai]: [WNATIVE[ChainId.xDai]],
[ChainId.Celo]: [WNATIVE[ChainId.Celo]],
}

export const BIPS_BASE = new BigNumber(10000)
Expand Down
4 changes: 4 additions & 0 deletions packages/mask/src/plugins/Trader/pipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export function resolveTradeProviderLink(tradeProvider: TradeProvider, networkTy
return 'https://aribitrum.api.0x.org/'
case NetworkType.xDai:
return 'https://xdai.api.0x.org/'
case NetworkType.Celo:
return 'https://celo.api.0x.org/'
default:
safeUnreachable(networkType)
return ''
Expand Down Expand Up @@ -134,6 +136,8 @@ export function resolveTradePairLink(tradeProvider: TradeProvider, address: stri
return `https://analytics-aribtrum.sushi.com/pairs/${address}`
case NetworkType.xDai:
return `https://analytics-xdai.sushi.com/pairs/${address}`
case NetworkType.Celo:
return `https://analytics-celo.sushi.com/pairs/${address}`
default:
safeUnreachable(networkType)
return ''
Expand Down
9 changes: 9 additions & 0 deletions packages/mask/src/plugins/Trader/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
polygonNetworkTradeProviderSettings,
arbitrumNetworkTradeProviderSettings,
xdaiNetworkTradeProviderSettings,
celoNetworkTradeProviderSettings,
} from './settings'
import { DataProvider, TradeProvider } from '@masknet/public-api'

Expand Down Expand Up @@ -41,6 +42,11 @@ currentChainIdSettings.addListener((chainId: ChainId) => {
if (currentDataProviderSettings.value === DataProvider.UNISWAP_INFO)
currentDataProviderSettings.value = DataProvider.COIN_MARKET_CAP
break
case NetworkType.Celo:
currentTradeProviderSettings.value = TradeProvider.SUSHISWAP
if (currentDataProviderSettings.value === DataProvider.UNISWAP_INFO)
currentDataProviderSettings.value = DataProvider.COIN_GECKO
break
default:
unreachable(networkType)
}
Expand All @@ -65,6 +71,9 @@ currentTradeProviderSettings.addListener((tradeProvider: TradeProvider) => {
case NetworkType.xDai:
xdaiNetworkTradeProviderSettings.value = tradeProvider
break
case NetworkType.Celo:
celoNetworkTradeProviderSettings.value = tradeProvider
break
default:
unreachable(networkType)
}
Expand Down
6 changes: 6 additions & 0 deletions packages/mask/src/plugins/Trader/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ export const xdaiNetworkTradeProviderSettings = createGlobalSettings<TradeProvid
{ primary: () => '' },
)

export const celoNetworkTradeProviderSettings = createGlobalSettings<TradeProvider>(
`${PLUGIN_IDENTIFIER}+celo+tradeProvider`,
TradeProvider.SUSHISWAP,
{ primary: () => '' },
)

//#region trade provider general settings
export interface TradeProviderSettings {
pools: ZrxTradePool[]
Expand Down
2 changes: 2 additions & 0 deletions packages/mask/src/plugins/Trader/trader/0x/useTrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export function getNativeTokenLabel(networkType: NetworkType) {
return '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
case NetworkType.xDai:
return '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
case NetworkType.Celo:
return '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
default:
safeUnreachable(networkType)
return ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
binanceNetworkTradeProviderSettings,
arbitrumNetworkTradeProviderSettings,
xdaiNetworkTradeProviderSettings,
celoNetworkTradeProviderSettings,
} from '../settings'
import { ChainId, getNetworkTypeFromChainId, NetworkType } from '@masknet/web3-shared-evm'
import { unreachable } from '@dimensiondev/kit'
Expand All @@ -18,6 +19,7 @@ export function useCurrentTradeProvider(chainId?: ChainId) {
const binanceNetworkTradeProvider = useValueRef(binanceNetworkTradeProviderSettings)
const arbitrumNetworkTradeProvider = useValueRef(arbitrumNetworkTradeProviderSettings)
const xdaiNetworkTradeProvider = useValueRef(xdaiNetworkTradeProviderSettings)
const celoNetworkTradeProvider = useValueRef(celoNetworkTradeProviderSettings)

if (!networkType) return TradeProvider.UNISWAP_V2
switch (networkType) {
Expand All @@ -31,6 +33,8 @@ export function useCurrentTradeProvider(chainId?: ChainId) {
return arbitrumNetworkTradeProvider
case NetworkType.xDai:
return xdaiNetworkTradeProvider
case NetworkType.Celo:
return celoNetworkTradeProvider
default:
unreachable(networkType)
}
Expand Down
1 change: 1 addition & 0 deletions packages/mask/src/plugins/Wallet/apis/debank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const chainIdMap: Record<number, string> = {
[ChainId.xDai]: 'xdai',
[ChainId.Matic]: 'matic',
[ChainId.Arbitrum]: 'arb',
[ChainId.Celo]: 'celo',
}

const getDebankChain = (chainId: number) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/mask/src/plugins/Wallet/pipes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const resolveDebankChainName = createLookupTableResolver<NetworkType, str
[NetworkType.Polygon]: 'matic',
[NetworkType.Arbitrum]: 'arb',
[NetworkType.xDai]: 'xdai',
[NetworkType.Celo]: 'celo',
},
'',
)
Expand All @@ -48,6 +49,7 @@ export const resolveZerionAssetsScopeName = createLookupTableResolver<NetworkTyp
[NetworkType.Polygon]: 'polygon-assets',
[NetworkType.Arbitrum]: 'arbitrum-assets',
[NetworkType.xDai]: 'xdai-assets',
[NetworkType.Celo]: 'celo-assets',
},
'',
)
Expand All @@ -59,6 +61,7 @@ export const resolveZerionTransactionsScopeName = createLookupTableResolver<Netw
[NetworkType.Polygon]: 'polygon-transactions',
[NetworkType.Arbitrum]: 'arbitrum-transactions',
[NetworkType.xDai]: 'xdai-transactions',
[NetworkType.Celo]: 'celo-transactions',
},
'',
)
Expand Down
1 change: 1 addition & 0 deletions packages/mask/src/plugins/Wallet/services/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,6 @@ export async function getSupportedNetworks() {
Flags.polygon_enabled ? NetworkType.Polygon : undefined,
Flags.arbitrum_enabled ? NetworkType.Arbitrum : undefined,
Flags.xdai_enabled ? NetworkType.xDai : undefined,
Flags.celo_enabled ? NetworkType.Celo : undefined,
].filter(Boolean) as NetworkType[]
}
Loading

0 comments on commit c5cfdf3

Please sign in to comment.