Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/sushiswap/sushiswap into …
Browse files Browse the repository at this point in the history
…ui-package-refactor
  • Loading branch information
LufyCZ committed Jun 20, 2024
2 parents 467af93 + ad0f77b commit d631a67
Show file tree
Hide file tree
Showing 33 changed files with 403 additions and 262 deletions.
4 changes: 2 additions & 2 deletions apis/extractor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
"dependencies": {
"@sentry/node": "7.110.0",
"@sushiswap/extractor": "workspace:*",
"@wagmi/core": "2.10.2",
"@wagmi/core": "2.10.6",
"cors": "2.8.5",
"dotenv": "16.3.1",
"express": "4.18.2",
"sushi": "workspace:*",
"viem": "2.10.11",
"wagmi": "2.9.2",
"wagmi": "2.9.12",
"zod": "3.21.4"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions apis/router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
"dependencies": {
"@sentry/node": "7.110.0",
"@sushiswap/extractor": "workspace:*",
"@wagmi/core": "2.10.2",
"@wagmi/core": "2.10.6",
"cors": "2.8.5",
"dotenv": "16.3.1",
"express": "4.18.2",
"sushi": "workspace:*",
"viem": "2.10.11",
"wagmi": "2.9.2",
"wagmi": "2.9.12",
"zod": "3.21.4"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion apis/tokens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@sushiswap/wagmi-config": "workspace:*",
"@upstash/redis": "1.22.1",
"@vercel/node": "3.0.9",
"@wagmi/core": "2.10.2",
"@wagmi/core": "2.10.6",
"drizzle-orm": "^0.29.5",
"postgres": "^3.4.3",
"sushi": "workspace:*",
Expand Down
5 changes: 5 additions & 0 deletions apps/evm/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ const nextConfig = bundleAnalyzer({
permanent: true,
destination: '/pool/:path*',
},
{
source: '/skale/swap',
permanent: true,
destination: '/swap?chainId=2046399126',
},
]
},
async rewrites() {
Expand Down
6 changes: 3 additions & 3 deletions apps/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
"@upstash/redis": "1.22.1",
"@vercel/analytics": "1.1.1",
"@vercel/edge-config": "0.4.1",
"@wagmi/connectors": "^5.0.2",
"@wagmi/core": "2.10.2",
"@wagmi/connectors": "^5.0.11",
"@wagmi/core": "2.10.6",
"cors": "2.8.5",
"d3": "7.8.4",
"date-fns": "2.30.0",
Expand Down Expand Up @@ -76,7 +76,7 @@
"swr": "2.1.5",
"tiny-invariant": "1.3.1",
"viem": "2.10.11",
"wagmi": "2.9.2",
"wagmi": "2.9.12",
"zod": "3.21.4"
},
"devDependencies": {
Expand Down
81 changes: 81 additions & 0 deletions apps/evm/src/app/api/faucet/skale-europa/[address]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { publicWagmiConfig } from '@sushiswap/wagmi-config'
import {
SendTransactionParameters,
createConfig,
getBalance,
getTransactionCount,
prepareTransactionRequest,
sendTransaction,
} from '@wagmi/core'
import { NextRequest, NextResponse } from 'next/server'
import { ChainId } from 'sushi'
import { Hex, getAddress } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { z } from 'zod'

const MAX_BALANCE_AMOUNT = 100000000000n // 0.0000001
const DISTRIBUTION_AMOUNT = 5000000000000n // 0.000005

const config = createConfig(publicWagmiConfig)
const account = process.env.SKALE_EUROPA_FAUCET_PRIVATE_KEY
? privateKeyToAccount(process.env.SKALE_EUROPA_FAUCET_PRIVATE_KEY as Hex)
: undefined

const schema = z.object({
address: z.string().transform((address) => getAddress(address)),
})

const trySendTransaction = async (
config: Parameters<typeof prepareTransactionRequest>[0],
params: SendTransactionParameters,
) => {
if (!account) throw new Error('SKALE_EUROPA_FAUCET_PRIVATE_KEY not set')
const nonce = await getTransactionCount(config, {
chainId: params.chainId,
address: account.address,
blockTag: 'pending',
})
const tx = await sendTransaction(config, {
...params,
nonce,
})
return tx
}

export async function GET(
_request: NextRequest,
{ params }: { params: { address: string } },
) {
try {
const { address } = schema.parse(params)

const balance = await getBalance(config, {
chainId: ChainId.SKALE_EUROPA,
address,
})

if (balance.value > MAX_BALANCE_AMOUNT)
throw new Error('User balance exceeds limit')

const tx = await trySendTransaction(config, {
chainId: ChainId.SKALE_EUROPA,
account,
to: address,
value: DISTRIBUTION_AMOUNT,
})

return NextResponse.json(tx, {
status: 200,
headers: {
'Cache-Control': 'public, max-age=5, stale-while-revalidate=60',
},
})
} catch (e) {
return NextResponse.json(e instanceof Error ? e.message : undefined, {
status: 500,
headers: {
'Cache-Control': 'public, max-age=5, stale-while-revalidate=60',
},
})
}
}
3 changes: 3 additions & 0 deletions apps/evm/src/app/pool/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import { Navigation } from '@sushiswap/ui'
import React, { FC } from 'react'
import { SUPPORTED_CHAIN_IDS } from 'src/config'
import { WagmiHeaderComponents } from 'src/lib/wagmi/components/wagmi-header-components'
import { useChainId } from 'wagmi'

export const Header: FC = () => {
const chainId = useChainId()
return (
<Navigation
rightElement={<WagmiHeaderComponents chainIds={SUPPORTED_CHAIN_IDS} />}
chainId={chainId}
/>
)
}
3 changes: 3 additions & 0 deletions apps/evm/src/app/swap/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import { Navigation } from '@sushiswap/ui'
import React, { FC } from 'react'
import { SUPPORTED_CHAIN_IDS } from 'src/config'
import { WagmiHeaderComponents } from 'src/lib/wagmi/components/wagmi-header-components'
import { useChainId } from 'wagmi'

export const Header: FC = () => {
const chainId = useChainId()
return (
<Navigation
rightElement={<WagmiHeaderComponents chainIds={SUPPORTED_CHAIN_IDS} />}
chainId={chainId}
/>
)
}
2 changes: 2 additions & 0 deletions apps/evm/src/app/swap/providers.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'use client'

import { ThemeProvider } from '@sushiswap/ui'
import { useSkaleEuropaFaucet } from 'src/lib/hooks'
import { CheckerProvider } from 'src/lib/wagmi/systems/Checker/Provider'

export function Providers({ children }: { children: React.ReactNode }) {
useSkaleEuropaFaucet()
return (
<ThemeProvider>
<CheckerProvider>{children}</CheckerProvider>
Expand Down
1 change: 1 addition & 0 deletions apps/evm/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const PREFERRED_CHAINID_ORDER = [
ChainId.ROOTSTOCK,
ChainId.BLAST,
ChainId.ZETACHAIN,
ChainId.SKALE_EUROPA,
ChainId.OPTIMISM,
ChainId.BSC,
ChainId.THUNDERCORE,
Expand Down
1 change: 1 addition & 0 deletions apps/evm/src/lib/hooks/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './useGraphPool'
export * from './usePoolGraphData'
export * from './useSkaleEuropaFaucet'
export * from './useSushiV2UserPositions'
40 changes: 40 additions & 0 deletions apps/evm/src/lib/hooks/api/useSkaleEuropaFaucet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use client'

import { publicWagmiConfig } from '@sushiswap/wagmi-config'
import { useQuery } from '@tanstack/react-query'
import { createConfig, getBalance } from '@wagmi/core'
import { ChainId } from 'sushi/chain'
import { Address } from 'viem'
import { useAccount } from 'wagmi'

const MAX_BALANCE_AMOUNT = 100000000000n // '0.0000001'

export const useSkaleEuropaFaucet = () => {
const { address, chainId } = useAccount()

return useQuery({
queryKey: ['useSkaleEuropaFaucet', address],
queryFn: async () => {
const config = createConfig(publicWagmiConfig)

const balance = await getBalance(config, {
chainId: ChainId.SKALE_EUROPA,
address: address as Address,
})

if (balance.value > MAX_BALANCE_AMOUNT) return false

const response = await fetch(`/api/faucet/skale-europa/${address}`)

const json = await response.json()

if (json.status !== 200) {
throw new Error(json)
}

return true
},
staleTime: Infinity,
enabled: Boolean(chainId === ChainId.SKALE_EUROPA && address),
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const DefaultView: FC<DefaultProps> = ({
onClick={() => setView(ProfileView.Transactions)}
hoverIconProps={{ width: 20, height: 20 }}
/>
<OnramperButton className="w-full">
<OnramperButton className="w-full" chainId={chainId}>
<List.MenuItem
icon={CreditCardIcon}
title="Buy Crypto"
Expand Down
2 changes: 1 addition & 1 deletion apps/evm/src/ui/pool/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const REWARDS_V3_APR_COLUMN: ColumnDef<AngleRewardsPool, unknown> = {
<Tooltip delayDuration={0}>
<TooltipTrigger asChild>
<span className="underline decoration-dotted underline-offset-2 flex items-center justify-end gap-1 text-sm text-gray-900 dark:text-slate-50">
{formatNumber(props.row.original.meanAPR || 0)}%
{formatPercent((props.row.original.meanAPR ?? 0) / 100)}
</span>
</TooltipTrigger>
<TooltipPrimitive.Portal>
Expand Down
49 changes: 0 additions & 49 deletions apps/evm/src/ui/swap/simple/simple-swap-additional-button.tsx

This file was deleted.

10 changes: 6 additions & 4 deletions apps/evm/src/ui/swap/simple/simple-swap-trade-review-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { useSimulateTrade } from 'src/lib/hooks/useSimulateTrade'
import { useSlippageTolerance } from 'src/lib/hooks/useSlippageTolerance'
import { useBalanceWeb3Refetch } from 'src/lib/wagmi/hooks/balances/useBalanceWeb3Refetch'
import { useApproved } from 'src/lib/wagmi/systems/Checker/Provider'
import { Chain } from 'sushi/chain'
import { Chain, ChainId } from 'sushi/chain'
import { Native } from 'sushi/currency'
import { shortenAddress } from 'sushi/format'
import { ZERO } from 'sushi/math'
Expand Down Expand Up @@ -458,9 +458,11 @@ export const SimpleSwapTradeReviewDialog: FC<{
</List.KeyValue>
)}
<List.KeyValue title="Network fee">
{isFetching ||
!trade?.gasSpent ||
trade.gasSpent === '0' ? (
{chainId === ChainId.SKALE_EUROPA ? (
'FREE'
) : isFetching ||
!trade?.gasSpent ||
trade.gasSpent === '0' ? (
<SkeletonText
align="right"
fontSize="sm"
Expand Down
6 changes: 4 additions & 2 deletions apps/evm/src/ui/swap/simple/simple-swap-trade-stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { Collapsible, Explainer, SkeletonBox, classNames } from '@sushiswap/ui'
import React, { FC } from 'react'
import { AddressToEnsResolver } from 'src/lib/wagmi/components/account/AddressToEnsResolver'
import { Chain } from 'sushi/chain'
import { Chain, ChainId } from 'sushi/chain'
import { Native } from 'sushi/currency'
import { shortenAddress } from 'sushi/format'
import { ZERO } from 'sushi/math'
Expand Down Expand Up @@ -104,7 +104,9 @@ export const SimpleSwapTradeStats: FC = () => {
Network fee
</span>
<span className="text-sm font-semibold text-gray-700 text-right dark:text-slate-400">
{loading || !trade?.gasSpent || trade.gasSpent === '0' ? (
{chainId === ChainId.SKALE_EUROPA ? (
'FREE'
) : loading || !trade?.gasSpent || trade.gasSpent === '0' ? (
<SkeletonBox className="h-4 py-0.5 w-[120px]" />
) : trade?.gasSpent ? (
`${trade.gasSpent} ${Native.onChain(chainId).symbol}`
Expand Down
2 changes: 0 additions & 2 deletions apps/evm/src/ui/swap/simple/simple-swap-widget.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { CrossChainBanner } from '../cross-chain-banner'
import { SwapModeButtons } from '../swap-mode-buttons'
import { SimpleSwapAdditionalButton } from './simple-swap-additional-button'
import { SimpleSwapBridgeBanner } from './simple-swap-bridge-banner'
import { SimpleSwapHeader } from './simple-swap-header'
import { SimpleSwapSettingsOverlay } from './simple-swap-settings-overlay'
Expand Down Expand Up @@ -28,7 +27,6 @@ export const SimpleSwapWidget = () => {
<div className="flex flex-col">
<SimpleSwapToken1Input />
<SimpleSwapTradeButton />
<SimpleSwapAdditionalButton />
</div>
<SimpleSwapTradeStats />
<SimpleSwapTokenNotFoundDialog />
Expand Down
Loading

0 comments on commit d631a67

Please sign in to comment.