-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/sushiswap/sushiswap into …
…ui-package-refactor
- Loading branch information
Showing
33 changed files
with
403 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
apps/evm/src/app/api/faucet/skale-europa/[address]/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 0 additions & 49 deletions
49
apps/evm/src/ui/swap/simple/simple-swap-additional-button.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.