Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feat/lifi
Browse files Browse the repository at this point in the history
  • Loading branch information
0xMasayoshi committed Dec 20, 2024
2 parents 88a6292 + 641a0e1 commit be7b6d1
Show file tree
Hide file tree
Showing 36 changed files with 650 additions and 674 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@
"https://www.artillery.io/schema.json": [
"file:///home/feedme/sushi/sushiswap/apis/router/test/load.yml"
]
}
},
"typescript.tsdk": "node_modules/typescript/lib"
}
2 changes: 1 addition & 1 deletion apis/token-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"devDependencies": {
"@tsconfig/esm": "1.0.4",
"@tsconfig/strictest": "2.0.2",
"typescript": "5.5.4",
"typescript": "5.7.2",
"vercel": "35.2.1"
}
}
4 changes: 2 additions & 2 deletions apps/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"class-variance-authority": "0.7.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"sushi": "4.1.12"
"sushi": "4.1.22"
},
"devDependencies": {
"@storybook/addon-a11y": "7.4.6",
Expand All @@ -43,7 +43,7 @@
"serve": "14.2.0",
"storybook": "7.4.6",
"tailwindcss": "3.3.2",
"typescript": "5.5.4",
"typescript": "5.7.2",
"vite": "4.3.9"
}
}
6 changes: 3 additions & 3 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@
"react-window": "1.8.7",
"sharp": "^0.33.5",
"strapi-sdk-js": "2.3.3",
"sushi": "4.1.12",
"sushi": "4.1.22",
"swr": "2.1.5",
"tiny-invariant": "1.3.1",
"tronweb": "5.3.2",
"viem": "2.21.4",
"viem": "2.21.55",
"wagmi": "2.12.10",
"zod": "3.23.8"
},
Expand Down Expand Up @@ -123,7 +123,7 @@
"schema-dts": "1.1.2",
"tailwindcss": "3.3.2",
"tsx": "4.19.0",
"typescript": "5.4.5",
"typescript": "5.7.2",
"vitest": "2.0.5"
}
}
3 changes: 0 additions & 3 deletions apps/web/src/app/(cms)/academy/[article-slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
}, []),
},
twitter: {
app: {
id: {},
},
card: isMediaVideo(article.cover.provider_metadata)
? 'player'
: 'summary_large_image',
Expand Down
22 changes: 22 additions & 0 deletions apps/web/src/app/(cms)/academy/article-list/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { getAcademyArticles } from '@sushiswap/graph-client/strapi'

export const revalidate = 3600

// For Mava's scraper
export default async function Page() {
const { articles } = await getAcademyArticles({
pagination: {
limit: 10_000,
},
})

return (
<div className="flex flex-col">
{articles.map((article) => (
<a key={article.id} href={`/academy/${article.slug}`}>
{article.title}
</a>
))}
</div>
)
}
4 changes: 4 additions & 0 deletions apps/web/src/app/(cms)/academy/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export default async function Page() {
<ViewMoreButton />
</div>
</Container>

<a href="/academy/article-list" className="hidden">
Article List
</a>
</div>
)
}
3 changes: 0 additions & 3 deletions apps/web/src/app/(cms)/blog/[article-slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
}, []),
},
twitter: {
app: {
id: {},
},
card: isMediaVideo(article.cover.provider_metadata)
? 'player'
: 'summary_large_image',
Expand Down
22 changes: 22 additions & 0 deletions apps/web/src/app/(cms)/blog/article-list/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { getBlogArticles } from '@sushiswap/graph-client/strapi'

export const revalidate = 3600

// For Mava's scraper
export default async function Page() {
const { articles } = await getBlogArticles({
pagination: {
limit: 10_000,
},
})

return (
<div className="flex flex-col">
{articles.map((article) => (
<a key={article.id} href={`/blog/${article.slug}`}>
{article.title}
</a>
))}
</div>
)
}
3 changes: 3 additions & 0 deletions apps/web/src/app/(cms)/blog/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export default function Page() {
</div>
<ArticleList />
</Container>
<a href="/blog/article-list" className="hidden">
Article List
</a>
</BlogSearchProvider>
</Suspense>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
'use client'

import { useQuery } from '@tanstack/react-query'
import { useEffect, useMemo } from 'react'
import {
type Address,
type ChainId,
Fraction,
withoutScientificNotation,
} from 'sushi'
import { getAddress, parseUnits } from 'viem'
import { parseUnits } from 'viem'
import { usePriceProvider } from './price-provider'

export type PriceMap = {
Expand All @@ -20,60 +19,6 @@ export type PriceMap = {
export function usePrices({
chainId,
enabled = true,
}: { chainId: ChainId | undefined; enabled?: boolean }): ReturnType<
typeof _usePrices
> {
const { data, isLoading, isFetching, isError } = useQuery({
queryKey: ['usePrices', chainId],
queryFn: async () => {
const res = await fetch(`https://api.sushi.com/price/v1/${chainId}`)
return res.json() as Promise<Record<Address, number>>
},
enabled: chainId && enabled,
refetchInterval: 15000,
refetchIntervalInBackground: false,
})

return useMemo(
() => ({
data: {
get: (address: Address) => {
if (data) {
return data[getAddress(address)]
}
},
has: (address: Address) => {
if (data) {
return getAddress(address) in data
}
return false
},
getFraction: (address: Address) => {
const price = data?.[getAddress(address)]
if (price) {
return new Fraction(
parseUnits(
withoutScientificNotation(String(price)) || '0',
18,
).toString(),
parseUnits('1', 18).toString(),
)
}
return undefined
},
},
lastModified: 0,
isLoading,
isUpdating: isFetching,
isError,
}),
[data, isLoading, isFetching, isError],
)
}

function _usePrices({
chainId,
enabled = true,
}: { chainId: ChainId | undefined; enabled?: boolean }) {
// Important to use state, not state.chains directly, as the reference to state.chains won't be changing and the component won't re-render
// It's not best practice, but it's controlled here in the hook and not exposed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const CurrencyIcon = ({
width: `${width}px`,
height: `${height}px`,
background: hashStringToColor(
`${currency?.symbol} ${currency?.name}` ?? '??',
currency ? `${currency.symbol} ${currency.name}` : '??',
),
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const Icon = ({ currency, height = 40, width = 40 }: IconProps) => {
width: `${width}px`,
height: `${height}px`,
background: hashStringToColor(
`${currency?.symbol} ${currency?.name}` ?? '??',
currency ? `${currency.symbol} ${currency.name}` : '??',
),
}}
>
Expand Down
15 changes: 5 additions & 10 deletions apps/web/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,10 @@ export const DISABLED_CHAIN_IDS = [
// NonStandardChainId.TRON,
] as const

export const NEW_CHAIN_IDS = [
ChainId.APE,
ChainId.MANTA,
ChainId.MODE,
ChainId.TAIKO,
ChainId.ZKLINK,
NonStandardChainId.TRON,
] as const
export const NEW_CHAIN_IDS = [ChainId.SONIC] as const

export const PREFERRED_CHAINID_ORDER = [
...NEW_CHAIN_IDS,
ChainId.ETHEREUM,
NonStandardChainId.TRON,
ChainId.BSC,
Expand All @@ -93,6 +87,7 @@ export const PREFERRED_CHAINID_ORDER = [
ChainId.MODE,
ChainId.GNOSIS,
ChainId.ROOTSTOCK,
ChainId.SONIC,
ChainId.KAVA,
ChainId.ZKSYNC_ERA,
ChainId.FANTOM,
Expand Down Expand Up @@ -234,8 +229,8 @@ export const ZAP_SUPPORTED_CHAIN_IDS = [
export type ZapSupportedChainId = (typeof ZAP_SUPPORTED_CHAIN_IDS)[number]
export const isZapSupportedChainId = (
chainId: number,
): chainId is ZapSupportedChainId =>
ZAP_SUPPORTED_CHAIN_IDS.includes(chainId as ZapSupportedChainId)
): chainId is ZapSupportedChainId => false
// ZAP_SUPPORTED_CHAIN_IDS.includes(chainId as ZapSupportedChainId)

export const XSWAP_SUPPORTED_CHAIN_IDS = [
ChainId.ARBITRUM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export type Props = Parameters<typeof useEnsName<PublicWagmiConfig>>[0] & {
children:
| ReactNode
| ReactNode[]
| ((payload: ReturnType<typeof useEnsName>) => JSX.Element)
| ((
payload: ReturnType<typeof useEnsName<PublicWagmiConfig>>,
) => JSX.Element)
}

export const AddressToEnsResolver = ({
Expand Down
5 changes: 5 additions & 0 deletions apps/web/src/lib/wagmi/hooks/approvals/hooks/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { erc20Abi_approve } from 'sushi/abi'
import { Address } from 'sushi/types'

export type ERC20ApproveABI = typeof erc20Abi_approve
export type ERC20ApproveArgs = [Address, bigint]
23 changes: 8 additions & 15 deletions apps/web/src/lib/wagmi/hooks/approvals/hooks/useTokenApproval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { createErrorToast, createToast } from '@sushiswap/notifications'
import { InterfaceEventName, sendAnalyticsEvent } from '@sushiswap/telemetry'
import { useCallback, useMemo, useState } from 'react'
import { erc20Abi_approve } from 'sushi/abi'
import { Amount, Type } from 'sushi/currency'
import {
Address,
Expand All @@ -17,6 +18,7 @@ import {
useWriteContract,
} from 'wagmi'

import { ERC20ApproveABI, ERC20ApproveArgs } from './types'
import { useTokenAllowance } from './useTokenAllowance'

export enum ApprovalState {
Expand Down Expand Up @@ -55,22 +57,13 @@ export const useTokenApproval = ({
enabled: Boolean(amount?.currency?.isToken && enabled),
})

const { data: simulation } = useSimulateContract({
const { data: simulation } = useSimulateContract<
ERC20ApproveABI,
'approve',
ERC20ApproveArgs
>({
chainId: amount?.currency.chainId,
abi: [
{
constant: false,
inputs: [
{ name: 'spender', type: 'address' },
{ name: 'amount', type: 'uint256' },
],
name: 'approve',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function',
},
] as const,
abi: erc20Abi_approve,
address: amount?.currency?.wrapped?.address as Address,
functionName: 'approve',
args: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { Token } from 'sushi/currency'
import { Address, UserRejectedRequestError } from 'viem'
import { usePublicClient, useSimulateContract, useWriteContract } from 'wagmi'
import { SendTransactionReturnType } from 'wagmi/actions'
import { ERC20ApproveABI, ERC20ApproveArgs } from './types'

interface UseTokenRevokeApproval {
account: Address | undefined
spender: Address
token: Token | undefined
token: Omit<Token, 'wrapped'> | undefined
}

export const useTokenRevokeApproval = ({
Expand All @@ -21,13 +22,17 @@ export const useTokenRevokeApproval = ({
}: UseTokenRevokeApproval) => {
const [isPending, setPending] = useState(false)
const client = usePublicClient()
const { data: simulation } = useSimulateContract({
address: token?.wrapped.address as Address,
const { data: simulation } = useSimulateContract<
ERC20ApproveABI,
'approve',
ERC20ApproveArgs
>({
address: token?.address as Address,
abi: erc20Abi_approve,
chainId: token?.chainId,
functionName: 'approve',
args: [spender, 0n],
query: { enabled: Boolean(token) },
query: { enabled: Boolean(account && spender && token?.address) },
})

const onSuccess = useCallback(
Expand Down
Loading

0 comments on commit be7b6d1

Please sign in to comment.