Skip to content
Closed
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
4 changes: 4 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
"multicall",
"multihop",
"mutex",
"nervos",
"newsfeed",
"nftrss",
"nftscan",
Expand Down Expand Up @@ -263,6 +264,9 @@
"xdai",
"xlarge",
"xlink",
"yokai",
"yokaiswap",
"yokayswap",
"zerion",
"zubin"
],
Expand Down
1 change: 1 addition & 0 deletions docs/evm-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,4 @@ Goto `chrome-extension://jkoeaghipilijlahjplgbfiocjhldnap/dashboard.html#/wallet
| xDai | <https://github.com/DimensionDev/Maskbook/pull/4140> |
| Arbitrum | <https://github.com/DimensionDev/Maskbook/pull/3558> |
| Avalanche | <https://github.com/DimensionDev/Maskbook/pull/5289> |
| Nervos | <https://github.com/DimensionDev/Maskbook/pull/> |
1 change: 1 addition & 0 deletions packages/mask/shared/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const Flags = {
flow_enabled: true,
celo_enabled: true,
aurora_enabled: true,
nervos_enabled: true,
nft_airdrop_enabled: false,
post_actions_enabled: false,
next_id_tip_enabled: false,
Expand Down
1 change: 1 addition & 0 deletions packages/mask/src/components/shared/ApplicationBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const SUPPORTED_CHAIN_ID_LIST = [
ChainId.Fantom,
ChainId.Aurora,
ChainId.Avalanche,
ChainId.Nervos,
]

export interface MaskAppEntry {
Expand Down
1 change: 1 addition & 0 deletions packages/mask/src/plugins/ITO/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const base: Plugin.Shared.Definition = {
ChainId.Aurora,
ChainId.Avalanche,
ChainId.Fantom,
ChainId.Nervos,
],
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/mask/src/plugins/NextID/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const base: Plugin.Shared.Definition = {
ChainId.Aurora,
ChainId.Avalanche,
ChainId.Fantom,
ChainId.Nervos,
],
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/mask/src/plugins/RedPacket/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const base: Plugin.Shared.Definition = {
ChainId.Fantom,
ChainId.Avalanche,
ChainId.Aurora,
ChainId.Nervos,
],
},
},
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 @@ -50,6 +50,8 @@ export async function getAvailableTraderProviders(chainId: ChainId) {
return [TradeProvider.SUSHISWAP]
case NetworkType.Aurora:
return [TradeProvider.DODO, TradeProvider.WANNASWAP, TradeProvider.TRISOLARIS]
case NetworkType.Nervos:
return [TradeProvider.YOKAISWAP]
case NetworkType.Boba:
case NetworkType.Fuse:
case NetworkType.Metis:
Expand Down
1 change: 1 addition & 0 deletions packages/mask/src/plugins/Trader/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const base: Plugin.Shared.Definition = {
ChainId.Aurora,
ChainId.Avalanche,
ChainId.Fantom,
ChainId.Nervos,
],
},
},
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 @@ -14,6 +14,7 @@ export const ZRX_BASE_URL: Record<NetworkType, string> = {
[NetworkType.Fuse]: '',
[NetworkType.Metis]: '',
[NetworkType.Optimistic]: '',
[NetworkType.Nervos]: '',
}

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 @@ -16,4 +16,5 @@ export const networkNames: Record<NetworkType, string> = {
[NetworkType.Fuse]: '',
[NetworkType.Metis]: '',
[NetworkType.Optimistic]: '',
[NetworkType.Nervos]: '',
}
1 change: 1 addition & 0 deletions packages/mask/src/plugins/Trader/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export * from './traderjoe'
export * from './pangolindex'
export * from './wannaswap'
export * from './trisolaris'
export * from './yokaiswap'
export type { ERC20TokenCustomizedBase, ERC20AgainstToken } from './types'
1 change: 1 addition & 0 deletions packages/mask/src/plugins/Trader/constants/openocean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export const networkNames: Record<NetworkType, string> = {
[NetworkType.Fuse]: '',
[NetworkType.Metis]: '',
[NetworkType.Optimistic]: '',
[NetworkType.Nervos]: '',
}
2 changes: 2 additions & 0 deletions packages/mask/src/plugins/Trader/constants/trader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const CUSD = createERC20Tokens('cUSD_ADDRESS', 'Celo Dollar', 'cUSD', 18)
export const CEUR = createERC20Tokens('cEUR_ADDRESS', 'Celo Euro', 'cEUR', 18)
export const JOE = createERC20Tokens('JOE_ADDRESS', 'JoeToken', 'JOE', 18)
export const PNG = createERC20Tokens('PNG_ADDRESS', 'Pangolin', 'PNG', 18)
export const YOK = createERC20Tokens('YOK_ADDRESS', 'Yokai', 'YOK', 8)

export const WNATIVE = createERC20Tokens(
'WNATIVE_ADDRESS',
Expand Down Expand Up @@ -77,6 +78,7 @@ export const WNATIVE_ONLY: ERC20AgainstToken = {
[ChainId.Fantom]: [WNATIVE[ChainId.Fantom]],
[ChainId.Aurora]: [WNATIVE[ChainId.Aurora]],
[ChainId.Aurora_Testnet]: [WNATIVE[ChainId.Aurora_Testnet]],
[ChainId.Nervos]: [WNATIVE[ChainId.Nervos]],
}

export const BIPS_BASE = new BigNumber(10000)
Expand Down
14 changes: 14 additions & 0 deletions packages/mask/src/plugins/Trader/constants/yokaiswap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ChainId } from '@masknet/web3-shared-evm'
import { DAI, ETHER, YOK, USDC, USDT, BUSD, WBTC, WNATIVE, WNATIVE_ONLY } from './trader'
import type { ERC20AgainstToken, ERC20TokenCustomizedBase } from './types'

/**
* Some tokens can only be swapped via certain pairs,
* so we override the list of bases that are considered for these tokens.
*/
export const YOKAISWAP_CUSTOM_BASES: ERC20TokenCustomizedBase = {}

export const YOKAISWAP_BASE_AGAINST_TOKENS: ERC20AgainstToken = {
...WNATIVE_ONLY,
[ChainId.Nervos]: [WNATIVE, YOK, DAI, USDT, USDC, ETHER, WBTC, BUSD].map((x) => x[ChainId.Nervos]),
}
1 change: 1 addition & 0 deletions packages/mask/src/plugins/Trader/pipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const resolveTradeProviderName = createLookupTableResolver<TradeProvider,
[TradeProvider.PANGOLIN]: 'PangolinDex',
[TradeProvider.TRISOLARIS]: 'Trisolaris',
[TradeProvider.WANNASWAP]: 'WannaSwap',
[TradeProvider.YOKAISWAP]: 'YokaiSwap',
},
(tradeProvider) => {
throw new Error(`Unknown provider type: ${tradeProvider}`)
Expand Down
1 change: 1 addition & 0 deletions packages/mask/src/plugins/Trader/trader/0x/useTrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function getNativeTokenLabel(networkType: NetworkType) {
case NetworkType.Metis:
case NetworkType.Avalanche:
case NetworkType.Optimistic:
case NetworkType.Nervos:
return NATIVE_TOKEN_ADDRESS
default:
safeUnreachable(networkType)
Expand Down
13 changes: 13 additions & 0 deletions packages/mask/src/plugins/Trader/trader/useAllTradeComputed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,18 @@ export function useAllTradeComputed(
const wannaswap = useUniswapTradeComputed(wannaswap_.value, inputToken, outputToken)
const wannaSwapEstimateGas = useUniswapTradeGasLimit(wannaswap, TradeProvider.WANNASWAP)

// Yokaiswap
const yokaiswap_ = useUniswapV2Trade(
TradeProvider.YOKAISWAP,
TradeStrategy.ExactIn,
inputAmount_,
'0',
tradeProviders.some((x) => x === TradeProvider.YOKAISWAP) ? inputToken : undefined,
tradeProviders.some((x) => x === TradeProvider.YOKAISWAP) ? outputToken : undefined,
)
const yokaiswap = useUniswapTradeComputed(yokaiswap_.value, inputToken, outputToken)
const yokaiswapEstimateGas = useUniswapTradeGasLimit(yokaiswap, TradeProvider.YOKAISWAP)

const allTradeResult = [
{ provider: TradeProvider.UNISWAP_V2, ...uniswapV2_, value: uniswapV2, gas: uniswapV2EstimateGas },
{ provider: TradeProvider.SUSHISWAP, ...sushiSwap_, value: sushiSwap, gas: sushiSwapEstimateGas },
Expand All @@ -263,6 +275,7 @@ export function useAllTradeComputed(
{ provider: TradeProvider.OPENOCEAN, ...openocean_, value: openocean, gas: openoceanSwapEstimateGas },
{ provider: TradeProvider.WANNASWAP, ...wannaswap_, value: wannaswap, gas: wannaSwapEstimateGas },
{ provider: TradeProvider.TRISOLARIS, ...trisolaris_, value: trisolaris, gas: trisolarisEstimateGas },
{ provider: TradeProvider.YOKAISWAP, ...yokaiswap_, value: yokaiswap, gas: yokaiswapEstimateGas },
]

return nativeToken_.value
Expand Down
14 changes: 14 additions & 0 deletions packages/mask/src/plugins/Trader/trader/useGetTradeContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
WANNASWAP_CUSTOM_BASES,
TRISOLARIS_BASE_AGAINST_TOKENS,
TRISOLARIS_CUSTOM_BASES,
YOKAISWAP_BASE_AGAINST_TOKENS,
YOKAISWAP_CUSTOM_BASES,
} from '../constants'
import { unreachable } from '@dimensiondev/kit'
import { TargetChainIdContext } from './useTargetChainIdContext'
Expand Down Expand Up @@ -150,6 +152,18 @@ export function useGetTradeContext(tradeProvider?: TradeProvider) {
ADDITIONAL_TOKENS: {},
CUSTOM_TOKENS: TRISOLARIS_CUSTOM_BASES,
}
case TradeProvider.YOKAISWAP:
return {
TYPE: tradeProvider,
IS_UNISWAP_V2_LIKE: true,
GRAPH_API: DEX_TRADE.YOKAISWAP_THEGRAPH,
INIT_CODE_HASH: DEX_TRADE.YOKAISWAP_INIT_CODE_HASH,
ROUTER_CONTRACT_ADDRESS: DEX_TRADE.YOKAISWAP_ROUTER_ADDRESS,
FACTORY_CONTRACT_ADDRESS: DEX_TRADE.YOKAISWAP_FACTORY_ADDRESS,
AGAINST_TOKENS: YOKAISWAP_BASE_AGAINST_TOKENS,
ADDITIONAL_TOKENS: {},
CUSTOM_TOKENS: YOKAISWAP_CUSTOM_BASES,
}
case TradeProvider.ZRX:
return {
TYPE: tradeProvider,
Expand Down
2 changes: 2 additions & 0 deletions packages/mask/src/plugins/Trader/trader/useTradeCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ export function useTradeCallback(
return uniswapV2Like
case TradeProvider.PANGOLIN:
return uniswapV2Like
case TradeProvider.YOKAISWAP:
return uniswapV2Like
case TradeProvider.OPENOCEAN:
return openocean
default:
Expand Down
14 changes: 14 additions & 0 deletions packages/mask/src/plugins/Trader/trader/useTradeContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
WANNASWAP_CUSTOM_BASES,
TRISOLARIS_CUSTOM_BASES,
TRISOLARIS_BASE_AGAINST_TOKENS,
YOKAISWAP_CUSTOM_BASES,
YOKAISWAP_BASE_AGAINST_TOKENS,
} from '../constants'
import type { TradeContext as TradeContext_ } from '../types'
import { TargetChainIdContext } from './useTargetChainIdContext'
Expand Down Expand Up @@ -171,6 +173,18 @@ export function useTradeContext(tradeProvider: TradeProvider) {
ADDITIONAL_TOKENS: {},
CUSTOM_TOKENS: PANGOLIN_CUSTOM_BASES,
}
case TradeProvider.YOKAISWAP:
return {
TYPE: tradeProvider,
IS_UNISWAP_V2_LIKE: true,
GRAPH_API: DEX_TRADE.YOKAISWAP_THEGRAPH,
INIT_CODE_HASH: DEX_TRADE.YOKAISWAP_INIT_CODE_HASH,
ROUTER_CONTRACT_ADDRESS: DEX_TRADE.YOKAISWAP_ROUTER_ADDRESS,
FACTORY_CONTRACT_ADDRESS: DEX_TRADE.YOKAISWAP_FACTORY_ADDRESS,
AGAINST_TOKENS: YOKAISWAP_BASE_AGAINST_TOKENS,
ADDITIONAL_TOKENS: {},
CUSTOM_TOKENS: YOKAISWAP_CUSTOM_BASES,
}
case TradeProvider.OPENOCEAN:
return {
TYPE: tradeProvider,
Expand Down
1 change: 1 addition & 0 deletions packages/mask/src/plugins/Trader/types/trader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export enum ZrxTradePool {
PangolinDex = 'PangolinDex',
Trisolaris = 'Trisolaris',
WannaSwap = 'WannaSwap',
YokaiSwap = 'YokaiSwap',
}

export interface TradeComputed<T = unknown> {
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 @@ -128,5 +128,6 @@ export async function getSupportedNetworks() {
Flags.fantom_enabled ? NetworkType.Fantom : undefined,
Flags.avalanche_enabled ? NetworkType.Avalanche : undefined,
Flags.aurora_enabled ? NetworkType.Aurora : undefined,
Flags.nervos_enabled ? NetworkType.Nervos : undefined,
].filter(Boolean) as NetworkType[]
}
2 changes: 2 additions & 0 deletions packages/public-api/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export enum NetworkType {
Fuse = 'Fuse',
Metis = 'Metis',
Optimistic = 'Optimistic',
Nervos = 'Nervos',
}

export enum DataProvider {
Expand All @@ -216,6 +217,7 @@ export enum TradeProvider {
TRISOLARIS = 12,
TRADERJOE = 13,
PANGOLIN = 14,
YOKAISWAP = 15,
}
/** Supported language settings */
export enum LanguageOptions {
Expand Down
1 change: 1 addition & 0 deletions packages/web3-constants/compile-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ compileConstants(path.join(__dirname, 'evm'), [
'Fantom',
'Aurora',
'Aurora_Testnet',
'Nervos',
])

compileConstants(path.join(__dirname, 'solana'), ['Mainnet', 'Testnet', 'Devnet'])
Expand Down
3 changes: 2 additions & 1 deletion packages/web3-constants/evm/airdrop.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"Celo": "",
"Fantom": "",
"Aurora": "",
"Aurora_Testnet": ""
"Aurora_Testnet": "",
"Nervos": ""
}
}
3 changes: 2 additions & 1 deletion packages/web3-constants/evm/artblocks.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"Celo": "",
"Fantom": "",
"Aurora": "",
"Aurora_Testnet": ""
"Aurora_Testnet": "",
"Nervos": ""
}
}
6 changes: 4 additions & 2 deletions packages/web3-constants/evm/coingecko.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"Celo": "celo",
"Fantom": "fantom",
"Aurora": "aurora",
"Aurora_Testnet": ""
"Aurora_Testnet": "",
"Nervos": ""
},
"COIN_ID": {
"Mainnet": "ethereum",
Expand All @@ -37,6 +38,7 @@
"Celo": "celo",
"Fantom": "fantom",
"Aurora": "ethereum",
"Aurora_Testnet": ""
"Aurora_Testnet": "",
"Nervos": ""
}
}
3 changes: 2 additions & 1 deletion packages/web3-constants/evm/coinmarketcap.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"Celo": "5567",
"Fantom": "3513",
"Aurora": "1313161554",
"Aurora_Testnet": ""
"Aurora_Testnet": "",
"Nervos": "71394"
}
}
9 changes: 6 additions & 3 deletions packages/web3-constants/evm/cryptoartai.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"Celo": "",
"Fantom": "",
"Aurora": "",
"Aurora_Testnet": ""
"Aurora_Testnet": "",
"Nervos": ""
},
"ARTIST_ACCEPTING_BIDS_V2": {
"Mainnet": "0x78C889749f29D2965a76Ede3BBb232A9729Ccf0b",
Expand All @@ -37,7 +38,8 @@
"Celo": "",
"Fantom": "",
"Aurora": "",
"Aurora_Testnet": ""
"Aurora_Testnet": "",
"Nervos": ""
},
"CANFT_MARKET": {
"Mainnet": "0x72d081953957723e540780a0C6bA31725469238E",
Expand All @@ -57,6 +59,7 @@
"Celo": "",
"Fantom": "",
"Aurora": "",
"Aurora_Testnet": ""
"Aurora_Testnet": "",
"Nervos": ""
}
}
3 changes: 2 additions & 1 deletion packages/web3-constants/evm/debank.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"Celo": "celo",
"Fantom": "ftm",
"Aurora": "aurora",
"Aurora_Testnet": ""
"Aurora_Testnet": "",
"Nervos": "nervos"
}
}
6 changes: 4 additions & 2 deletions packages/web3-constants/evm/dhedge.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"Celo": "",
"Fantom": "",
"Aurora": "",
"Aurora_Testnet": ""
"Aurora_Testnet": "",
"Nervos": ""
},
"API_URL": {
"Mainnet": "https://api-v2.dhedge.org/graphql",
Expand All @@ -37,6 +38,7 @@
"Celo": "",
"Fantom": "",
"Aurora": "",
"Aurora_Testnet": ""
"Aurora_Testnet": "",
"Nervos": ""
}
}
Loading