-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into renovate/solana-web3.js-1.x
- Loading branch information
Showing
33 changed files
with
528 additions
and
364 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,10 +50,10 @@ | |
"@solana/wallet-adapter-wallets": "0.19.32", | ||
"@solana/web3.js": "1.95.3", | ||
"@tanstack/react-query": "5.24.8", | ||
"@wagmi/connectors": "5.1.5", | ||
"@wagmi/connectors": "5.1.9", | ||
"@wagmi/core": "2.13.4", | ||
"@walletconnect/ethereum-provider": "2.15.2", | ||
"@walletconnect/utils": "2.15.2", | ||
"@walletconnect/ethereum-provider": "2.16.1", | ||
"@walletconnect/utils": "2.16.1", | ||
"@web3modal/base": "workspace:*", | ||
"@web3modal/ethers": "workspace:*", | ||
"@web3modal/ethers5": "workspace:*", | ||
|
@@ -63,7 +63,7 @@ | |
"@web3modal/wallet": "workspace:*", | ||
"axios": "1.7.2", | ||
"bs58": "6.0.0", | ||
"ethers": "6.13.0", | ||
"ethers": "6.13.2", | ||
"ethers5": "npm:[email protected]", | ||
"framer-motion": "10.17.9", | ||
"next": "14.2.3", | ||
|
@@ -73,8 +73,8 @@ | |
"react-icons": "4.12.0", | ||
"rpc-websockets": "7.11.0", | ||
"valtio": "1.11.2", | ||
"viem": "2.19.6", | ||
"wagmi": "2.12.5", | ||
"viem": "2.21.4", | ||
"wagmi": "2.12.9", | ||
"webauthn-p256": "0.0.2" | ||
}, | ||
"devDependencies": { | ||
|
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
122 changes: 122 additions & 0 deletions
122
apps/laboratory/src/components/Solana/SolanaSignJupiterSwapTest.tsx
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,122 @@ | ||
import { useState } from 'react' | ||
import { Button, Stack, Text, Spacer } from '@chakra-ui/react' | ||
import { PublicKey, VersionedTransaction } from '@solana/web3.js' | ||
|
||
import { useWeb3ModalAccount, useWeb3ModalProvider } from '@web3modal/solana/react' | ||
|
||
import { solana } from '../../utils/ChainsUtil' | ||
import { useChakraToast } from '../Toast' | ||
import bs58 from 'bs58' | ||
|
||
export function SolanaSignJupiterSwapTest() { | ||
const toast = useChakraToast() | ||
const { chainId } = useWeb3ModalAccount() | ||
const { walletProvider, connection } = useWeb3ModalProvider() | ||
const [loading, setLoading] = useState(false) | ||
|
||
async function onSignVersionedTransaction() { | ||
try { | ||
setLoading(true) | ||
if (!walletProvider?.publicKey) { | ||
throw Error('user is disconnected') | ||
} | ||
|
||
if (!connection) { | ||
throw Error('no connection set') | ||
} | ||
|
||
const transaction = await createJupiterSwapTransaction({ | ||
publicKey: walletProvider.publicKey | ||
}) | ||
const signedTransaction = await walletProvider.signTransaction(transaction) | ||
const signature = signedTransaction.signatures[0] | ||
|
||
if (!signature) { | ||
throw Error('Empty signature') | ||
} | ||
|
||
toast({ | ||
title: 'Success', | ||
description: bs58.encode(signature), | ||
type: 'success' | ||
}) | ||
} catch (err) { | ||
toast({ | ||
title: 'Error', | ||
description: (err as Error).message, | ||
type: 'error' | ||
}) | ||
} finally { | ||
setLoading(false) | ||
} | ||
} | ||
|
||
if (chainId === solana.chainId) { | ||
return ( | ||
<Text fontSize="md" color="yellow"> | ||
Switch to Solana Devnet or Testnet to test this feature | ||
</Text> | ||
) | ||
} | ||
|
||
return ( | ||
<Stack direction={['column', 'column', 'row']}> | ||
<Button | ||
data-test-id="sign-transaction-button" | ||
onClick={onSignVersionedTransaction} | ||
isDisabled={loading} | ||
> | ||
Sign Jupiter Swap Transaction | ||
</Button> | ||
<Spacer /> | ||
</Stack> | ||
) | ||
} | ||
|
||
type CreateJupiterSwapTransactionParams = { | ||
publicKey: PublicKey | ||
} | ||
|
||
async function createJupiterSwapTransaction({ publicKey }: CreateJupiterSwapTransactionParams) { | ||
const qs = new URLSearchParams({ | ||
inputMint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', | ||
outputMint: 'So11111111111111111111111111111111111111112', | ||
amount: '100000', | ||
slippageBps: '300', | ||
swapMode: 'ExactIn', | ||
onlyDirectRoutes: 'false', | ||
asLegacyTransaction: 'false', | ||
maxAccounts: '64', | ||
minimizeSlippage: 'false' | ||
}) | ||
|
||
const quoteResponse = await ( | ||
await fetch(`https://quote-api.jup.ag/v6/quote?${qs.toString()}`) | ||
).json() | ||
const swapResponse = await ( | ||
await fetch('https://quote-api.jup.ag/v6/swap', { | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ | ||
userPublicKey: publicKey.toString(), | ||
wrapAndUnwrapSol: true, | ||
prioritizationFeeLamports: { | ||
priorityLevelWithMaxLamports: { | ||
maxLamports: 4000000, | ||
global: false, | ||
priorityLevel: 'high' | ||
} | ||
}, | ||
asLegacyTransaction: false, | ||
dynamicComputeUnitLimit: true, | ||
allowOptimizedWrappedSolTokenAccount: false, | ||
quoteResponse, | ||
dynamicSlippage: { maxBps: 300 } | ||
}), | ||
method: 'POST' | ||
}) | ||
).json() | ||
|
||
return VersionedTransaction.deserialize(Buffer.from(swapResponse.swapTransaction, 'base64')) | ||
} |
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
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
Oops, something went wrong.