Skip to content

Commit

Permalink
feat: add sonic
Browse files Browse the repository at this point in the history
  • Loading branch information
viet-nv committed Dec 17, 2024
1 parent db1a67c commit 3dfca83
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 47 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@holdstation/paymaster-helper": "^2.0.20",
"@kyberswap/ks-sdk-classic": "^1.0.3",
"@kyberswap/ks-sdk-core": "1.1.6",
"@kyberswap/ks-sdk-core": "1.1.7",
"@kyberswap/ks-sdk-elastic": "^1.1.2",
"@kyberswap/oauth2": "1.0.2",
"@lingui/macro": "^4.6.0",
Expand Down Expand Up @@ -117,7 +117,7 @@
"swiper": "^8.4.4",
"ua-parser-js": "^1.0.33",
"util": "^0.12.5",
"viem": "^2.20.0",
"viem": "^2.21.55",
"vite-plugin-env-compatible": "^1.1.1",
"wagmi": "^2.12.25",
"walktour": "^5.2.0",
Expand Down Expand Up @@ -197,7 +197,7 @@
"vite-tsconfig-paths": "^4.0.8"
},
"resolutions": {
"@kyberswap/ks-sdk-core": "1.1.6",
"@kyberswap/ks-sdk-core": "1.1.7",
"babel-plugin-lodash/@babel/types": "~7.20.0",
"react-error-overlay": "6.0.9"
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ClassicElasticTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function ClassicElasticTab() {
ChainId.SCROLL,
ChainId.BLAST,
ChainId.MANTLE,
ChainId.XLAYER,
ChainId.SONIC,
].includes(chainId)

const showLegacyExplicit =
Expand Down
4 changes: 2 additions & 2 deletions src/components/Web3Provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
polygon,
polygonZkEvm,
scroll,
xLayer,
sonic,
zksync,
} from 'viem/chains'
import { Connector, WagmiProvider, createConfig, createConnector, useConnect } from 'wagmi'
Expand Down Expand Up @@ -158,7 +158,7 @@ export const wagmiConfig = createConfig({
avalanche,
fantom,
blast,
xLayer,
sonic,
],
connectors: [
injectedWithFallback(),
Expand Down
2 changes: 1 addition & 1 deletion src/constants/bases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const WETH_ONLY: ChainTokenList = {
[ChainId.SCROLL]: [WETH[ChainId.SCROLL]],
[ChainId.BLAST]: [WETH[ChainId.BLAST]],
[ChainId.MANTLE]: [WETH[ChainId.MANTLE]],
[ChainId.XLAYER]: [WETH[ChainId.XLAYER]],
[ChainId.SONIC]: [WETH[ChainId.SONIC]],
}

// used to construct intermediary pairs for trading
Expand Down
6 changes: 3 additions & 3 deletions src/constants/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
mumbai,
optimism,
scroll,
xlayer,
sonic,
zkEvm,
zksync,
} from './networks/index'
Expand All @@ -45,7 +45,7 @@ const NETWORKS_INFO_CONFIG: NETWORKS_INFO_CONFIG_TYPE = {
[ChainId.SCROLL]: scroll,
[ChainId.BLAST]: blast,
[ChainId.MANTLE]: mantle,
[ChainId.XLAYER]: xlayer,
[ChainId.SONIC]: sonic,
} as const

//this Proxy helps fallback undefined ChainId by Ethereum info
Expand Down Expand Up @@ -74,7 +74,7 @@ export const MAINNET_NETWORKS = [
ChainId.FANTOM,
ChainId.BLAST,
ChainId.MANTLE,
ChainId.XLAYER,
ChainId.SONIC,
] as const

// These option of walletconnect is not support by wallets properly
Expand Down
2 changes: 1 addition & 1 deletion src/constants/networks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export { default as zkEvm } from './zkevm'
export { default as base } from './base'
export { default as scroll } from './scroll'
export { default as blast } from './blast'
export { default as xlayer } from './xlayer'
export { default as sonic } from './sonic'
export { default as mantle } from './mantle'
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@ import { NetworkInfo } from 'constants/networks/type'
const EMPTY_ARRAY: any[] = []
const NOT_SUPPORT = null

const x1: NetworkInfo = {
chainId: ChainId.XLAYER,
route: 'xlayer',
ksSettingRoute: 'xlayer',
priceRoute: 'xlayer',
poolFarmRoute: 'xlayer',
aggregatorRoute: 'xlayer',
name: 'X Layer',
icon: 'https://storage.googleapis.com/ks-setting-1d682dca/bafc6027-7c84-4517-8fbd-f18fda18c5b91709787884512.png',
const sonic: NetworkInfo = {
chainId: ChainId.SONIC,
route: 'sonic',
ksSettingRoute: 'sonic',
priceRoute: 'sonic',
poolFarmRoute: 'sonic',
aggregatorRoute: 'sonic',
name: 'Sonic',
icon: 'https://www.soniclabs.com/favicon.ico',

iconSelected: NOT_SUPPORT,

defaultBlockSubgraph: '',
etherscanUrl: 'https://www.okx.com/explorer/xlayer',
etherscanName: 'X Layer Explorer',
bridgeURL: 'https://www.okx.com/xlayer/bridge',
etherscanUrl: 'https://sonicscan.org',
etherscanName: 'Sonic scan',
bridgeURL: 'https://gw.fantom.network',
nativeToken: {
symbol: 'OKB',
name: 'OKB',
logo: 'https://s2.coinmarketcap.com/static/img/coins/64x64/3897.png',
symbol: 'S',
name: 'S',
logo: 'https://www.soniclabs.com/favicon.ico',
decimal: 18,
minForGas: 10 ** 16,
minForGas: 2 * 10 ** 17,
},
defaultRpcUrl: 'https://rpc.xlayer.tech',
defaultRpcUrl: 'https://rpc.soniclabs.com',
multicall: '0xcA11bde05977b3631167028862bE2a173976CA11',
classic: {
defaultSubgraph: '',
Expand Down Expand Up @@ -66,10 +66,10 @@ const x1: NetworkInfo = {
},
limitOrder: '*',
averageBlockTimeInSeconds: 2.0, // dont use for base
coingeckoNetworkId: 'xlayer',
coingeckoNativeTokenId: 'okb',
coingeckoNetworkId: 'sonic',
coingeckoNativeTokenId: 's',
dexToCompare: NOT_SUPPORT,
geckoTermialId: NOT_SUPPORT,
}

export default x1
export default sonic
10 changes: 5 additions & 5 deletions src/constants/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const STABLE_COIN_ADDRESSES_TO_TAKE_FEE: Record<ChainId, string[]> = {
[ChainId.SCROLL]: [],
[ChainId.BLAST]: [],
[ChainId.MANTLE]: [],
[ChainId.XLAYER]: [],
[ChainId.SONIC]: [],
}

// This is basically the same as STABLE_COIN_ADDRESSES_TO_TAKE_FEE,
Expand Down Expand Up @@ -117,7 +117,7 @@ export const SUPER_STABLE_COINS_ADDRESS: { [chainId in ChainId]: string[] } = {
[ChainId.SCROLL]: [],
[ChainId.BLAST]: [],
[ChainId.MANTLE]: [],
[ChainId.XLAYER]: [],
[ChainId.SONIC]: [],
}

export const CORRELATED_COINS_ADDRESS: { [chainId in ChainId]: string[][] } = {
Expand Down Expand Up @@ -389,7 +389,7 @@ export const CORRELATED_COINS_ADDRESS: { [chainId in ChainId]: string[][] } = {
[ChainId.SCROLL]: [],
[ChainId.BLAST]: [],
[ChainId.MANTLE]: [],
[ChainId.XLAYER]: [],
[ChainId.SONIC]: [],
}

export const KNC_ADDRESS = '0xdeFA4e8a7bcBA345F687a2f1456F5Edd9CE97202'
Expand All @@ -415,7 +415,7 @@ export const KNC: { [chainId in ChainId]: Token } = {
[ChainId.ZKSYNC]: new Token(ChainId.ZKSYNC, KNC_ADDRESS, 18, 'KNC', 'KNC'),
[ChainId.BLAST]: new Token(ChainId.BLAST, KNC_ADDRESS, 18, 'KNC', 'KNC'),
[ChainId.MANTLE]: new Token(ChainId.MANTLE, KNC_ADDRESS, 18, 'KNC', 'KNC'),
[ChainId.XLAYER]: new Token(ChainId.MANTLE, KNC_ADDRESS, 18, 'KNC', 'KNC'),
[ChainId.SONIC]: new Token(ChainId.SONIC, KNC_ADDRESS, 18, 'KNC', 'KNC'),

[ChainId.AVAXTESTNET]: new Token(ChainId.AVAXTESTNET, KNC_ADDRESS, 18, 'KNC', 'KNC'),
[ChainId.MUMBAI]: new Token(ChainId.MUMBAI, '0xFD1f9381Cb641Dc76Fe8087dbcf8ea84a2c77cbE', 18, 'KNC', 'KNC'),
Expand Down Expand Up @@ -443,7 +443,7 @@ export const DEFAULT_OUTPUT_TOKEN_BY_CHAIN: Partial<Record<ChainId, Token>> = {
[ChainId.SCROLL]: new Token(ChainId.SCROLL, '0xf55BEC9cafDbE8730f096Aa55dad6D22d44099Df', 6, 'USDT', 'Tether USD'),
[ChainId.BLAST]: new Token(ChainId.BLAST, '0x4300000000000000000000000000000000000003', 18, 'USDB', 'USDB'),
[ChainId.MANTLE]: new Token(ChainId.MANTLE, '0x201EBa5CC46D216Ce6DC03F6a759e8E766e956aE', 6, 'USDT', 'USDT'),
[ChainId.XLAYER]: new Token(ChainId.XLAYER, '0x1e4a5963abfd975d8c9021ce480b42188849d41d', 6, 'USDT', 'USDT'),
[ChainId.SONIC]: new Token(ChainId.SONIC, '0x391071Fe567d609E4af9d32de726d4C33679C7e2', 6, 'USDC', 'USDC'),
}

export const DEFAULT_SWAP_FEE_STABLE_PAIRS = 4
Expand Down
5 changes: 1 addition & 4 deletions src/pages/About/AboutKyberSwap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,7 @@ function AboutKyberSwap() {

<img src="https://www.mantle.xyz/logo-lockup.svg" alt="mantle" width="100%" />

<Flex alignItems="center" sx={{ minWidth: '190px', gap: '6px' }}>
<img src="https://static.okx.com/cdn/assets/imgs/243/230501A8E74482AB.png" alt="X Layer" width="50px" />
<Text>X Layer</Text>
</Flex>
<img src="https://www.soniclabs.com/sonic-logo.svg" alt="Sonic" width="100%" />
</Powered>
</Text>
</Wrapper>
Expand Down
12 changes: 10 additions & 2 deletions src/state/swap/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,11 @@ export const useInputCurrency = () => {
const allTokens = useAllTokens()

const token = useMemo(() => {
return Object.values(allTokens).find(item => item?.symbol?.toLowerCase() === fromCurrency.toLowerCase())
return Object.values(allTokens).find(
item =>
item?.symbol?.toLowerCase() === fromCurrency.toLowerCase() ||
item.address.toLowerCase() === fromCurrency.toLowerCase(),
)
}, [allTokens, fromCurrency])

const inputCurrency = useCurrencyV2(token ? token.address : fromCurrency)
Expand All @@ -272,7 +276,11 @@ export const useOutputCurrency = () => {
const allTokens = useAllTokens()

const token = useMemo(() => {
return Object.values(allTokens).find(item => item?.symbol?.toLowerCase() === toCurrency.toLowerCase())
return Object.values(allTokens).find(
item =>
item?.symbol?.toLowerCase() === toCurrency.toLowerCase() ||
item.address.toLowerCase() === toCurrency.toLowerCase(),
)
}, [allTokens, toCurrency])

const outputCurrency = useCurrencyV2(token ? token.address : toCurrency)
Expand Down
Loading

0 comments on commit 3dfca83

Please sign in to comment.