merge main

This commit is contained in:
saml33 2024-02-08 12:18:39 +11:00
commit 7b787ed48b
9 changed files with 67 additions and 124 deletions

View File

@ -5,11 +5,7 @@ import { ChangeEvent, useCallback, useEffect, useMemo, useState } from 'react'
import mangoStore, { CLUSTER } from '@store/mangoStore'
import { Token } from 'types/jupiter'
import { handleGetRoutes } from '@components/swap/useQuoteRoutes'
import {
JUPITER_PRICE_API_MAINNET,
JUPITER_REFERRAL_PK,
USDC_MINT,
} from 'utils/constants'
import { JUPITER_PRICE_API_MAINNET, USDC_MINT } from 'utils/constants'
import { PublicKey, SYSVAR_RENT_PUBKEY, Transaction } from '@solana/web3.js'
import { useWallet } from '@solana/wallet-adapter-react'
import {
@ -57,7 +53,6 @@ import {
LISTING_PRESETS_KEY,
} from '@blockworks-foundation/mango-v4-settings/lib/helpers/listingTools'
import Checkbox from '@components/forms/Checkbox'
import { ReferralProvider } from '@jup-ag/referral-sdk'
import { BN } from '@coral-xyz/anchor'
import Select from '@components/forms/Select'
import { WRAPPED_SOL_MINT } from '@metaplex-foundation/js'
@ -164,6 +159,27 @@ const ListToken = ({ goBack }: { goBack: () => void }) => {
}))
}, [preset])
useEffect(() => {
const handleOracleUpdate = async () => {
if (currentTokenInfo) {
setLoadingListingParams(true)
const { oraclePk, isPyth } = await getOracle({
baseSymbol: currentTokenInfo.symbol,
quoteSymbol: 'usd',
connection,
targetAmount: proposedPreset.preset_target_amount,
})
setAdvForm({
...advForm,
oraclePk: oraclePk || '',
})
setLoadingListingParams(false)
setIsPyth(isPyth)
}
}
handleOracleUpdate()
}, [proposedPreset.preset_name])
const quoteBank = group?.getFirstBankByMint(new PublicKey(USDC_MINT))
const minVoterWeight = useMemo(
() =>
@ -206,14 +222,14 @@ const ListToken = ({ goBack }: { goBack: () => void }) => {
}
const getListingParams = useCallback(
async (tokenInfo: Token, targetAmount: number) => {
async (tokenInfo: Token) => {
setLoadingListingParams(true)
const [{ oraclePk, isPyth }, marketPk] = await Promise.all([
getOracle({
baseSymbol: tokenInfo.symbol,
quoteSymbol: 'usd',
connection,
targetAmount: targetAmount,
targetAmount: 0,
}),
getBestMarket({
baseMint: mint,
@ -268,7 +284,6 @@ const ListToken = ({ goBack }: { goBack: () => void }) => {
onlyDirect = false,
) => {
const SLIPPAGE_BPS = 50
const FEE = 0
const walletForCheck = wallet.publicKey
? wallet.publicKey?.toBase58()
: emptyPk
@ -279,7 +294,6 @@ const ListToken = ({ goBack }: { goBack: () => void }) => {
toNative(amount, 6).toNumber(),
SLIPPAGE_BPS,
mode,
FEE,
walletForCheck,
undefined, // mangoAccount
'JUPITER',
@ -430,8 +444,8 @@ const ListToken = ({ goBack }: { goBack: () => void }) => {
setBaseTokenPrice(priceInfo.data[mint]?.price || 0)
setCurrentTokenInfo(tokenInfo)
if (tokenInfo) {
const targetAmount = await handleLiquidityCheck(new PublicKey(mint))
getListingParams(tokenInfo, targetAmount)
await handleLiquidityCheck(new PublicKey(mint))
getListingParams(tokenInfo)
}
}, [getListingParams, handleLiquidityCheck, jupiterTokens, mint, t])
@ -602,21 +616,6 @@ const ListToken = ({ goBack }: { goBack: () => void }) => {
.instruction()
proposalTx.push(registerMarketix)
}
const rp = new ReferralProvider(connection)
const tx = await rp.initializeReferralTokenAccount({
payerPubKey: advForm.fastListing
? MANGO_DAO_FAST_LISTING_WALLET
: MANGO_DAO_WALLET,
referralAccountPubKey: JUPITER_REFERRAL_PK,
mint: mint,
})
const isExistingAccount =
(await connection.getBalance(tx.referralTokenAccountPubKey)) > 1
if (!isExistingAccount) {
proposalTx.push(...tx.tx.instructions)
}
const walletSigner = wallet as never
setCreatingProposal(true)
@ -678,13 +677,13 @@ const ListToken = ({ goBack }: { goBack: () => void }) => {
const closeCreateOpenBookMarketModal = () => {
setCreateOpenbookMarket(false)
if (currentTokenInfo && proposedPresetTargetAmount) {
getListingParams(currentTokenInfo, proposedPresetTargetAmount)
getListingParams(currentTokenInfo)
}
}
const closeCreateOracleModal = () => {
setOracleModalOpen(false)
if (currentTokenInfo && proposedPresetTargetAmount) {
getListingParams(currentTokenInfo, proposedPresetTargetAmount)
getListingParams(currentTokenInfo)
}
}

View File

@ -182,24 +182,7 @@ export const fetchJupiterWalletSwapTransaction = async (
selectedRoute: JupiterV6RouteInfo,
userPublicKey: PublicKey,
slippage: number,
inputMint: PublicKey,
outputMint: PublicKey,
): Promise<VersionedTransaction> => {
// TODO: replace by something that belongs to the DAO
// https://referral.jup.ag/
// EV4qhLE2yPKdUPdQ74EWJUn21xT3eGQxG3DRR1g9NNFc belongs to 8SSLjXBEVk9nesbhi9UMCA32uijbVBUqWoKPPQPTekzt
// for now
const feeMint = selectedRoute.swapMode === 'ExactIn' ? outputMint : inputMint
const feeAccountPdas = await PublicKey.findProgramAddressSync(
[
Buffer.from('referral_ata'),
new PublicKey('EV4qhLE2yPKdUPdQ74EWJUn21xT3eGQxG3DRR1g9NNFc').toBuffer(),
feeMint.toBuffer(),
],
new PublicKey('REFER4ZgmyYx9c6He5XfaTMiGfdLwRnkV4RPp9t9iF3'),
)
const feeAccount = feeAccountPdas[0]
// docs https://station.jup.ag/api-v6/post-swap
const transactions = await (
await fetch(`${JUPITER_V6_QUOTE_API_MAINNET}/swap`, {
@ -213,16 +196,6 @@ export const fetchJupiterWalletSwapTransaction = async (
// user public key to be used for the swap
userPublicKey,
slippageBps: Math.ceil(slippage * 100),
// docs
// https://station.jup.ag/docs/additional-topics/referral-program
// https://github.com/TeamRaccoons/referral
// https://github.com/TeamRaccoons/referral/blob/main/packages/sdk/src/referral.ts
...(feeMint.toBase58() ===
'HZ1JovNiVvGrGNiiYvEozEVgZ58xaU3RKwX8eACQBCt3'
? {}
: { platformFeeBps: 1, feeAccount }),
// limits
}),
})
).json()
@ -243,22 +216,6 @@ export const fetchJupiterTransaction = async (
inputMint: PublicKey,
outputMint: PublicKey,
): Promise<[TransactionInstruction[], AddressLookupTableAccount[]]> => {
// TODO: replace by something that belongs to the DAO
// https://referral.jup.ag/
// EV4qhLE2yPKdUPdQ74EWJUn21xT3eGQxG3DRR1g9NNFc belongs to 8SSLjXBEVk9nesbhi9UMCA32uijbVBUqWoKPPQPTekzt
// for now
const feeMint = selectedRoute.swapMode === 'ExactIn' ? outputMint : inputMint
const feeAccountPdas = await PublicKey.findProgramAddressSync(
[
Buffer.from('referral_ata'),
new PublicKey('EV4qhLE2yPKdUPdQ74EWJUn21xT3eGQxG3DRR1g9NNFc').toBuffer(),
feeMint.toBuffer(),
],
new PublicKey('REFER4ZgmyYx9c6He5XfaTMiGfdLwRnkV4RPp9t9iF3'),
)
const feeAccount = feeAccountPdas[0]
// docs https://station.jup.ag/api-v6/post-swap
const transactions = await (
await fetch(`${JUPITER_V6_QUOTE_API_MAINNET}/swap`, {
@ -273,13 +230,6 @@ export const fetchJupiterTransaction = async (
userPublicKey,
slippageBps: Math.ceil(slippage * 100),
wrapAndUnwrapSol: false,
// docs
// https://station.jup.ag/docs/additional-topics/referral-program
// https://github.com/TeamRaccoons/referral
// https://github.com/TeamRaccoons/referral/blob/main/packages/sdk/src/referral.ts
...([''].includes(feeMint.toBase58())
? {}
: { platformFeeBps: 1, feeAccount }),
}),
})
).json()
@ -422,8 +372,6 @@ const SwapReviewRouteInfo = ({
selectedRoute,
wallet.publicKey,
slippage,
inputBank.mint,
outputBank.mint,
)
const latestBlockhash = await connection.getLatestBlockhash()
const sign = wallet.signTransaction!

View File

@ -29,7 +29,6 @@ const fetchJupiterRoute = async (
amount = 0,
slippage = 50,
swapMode = 'ExactIn',
feeBps = 1,
onlyDirectRoutes = true,
maxAccounts = 64,
) => {
@ -41,7 +40,6 @@ const fetchJupiterRoute = async (
outputMint: outputMint.toString(),
amount: amount.toString(),
slippageBps: Math.ceil(slippage * 100).toString(),
platformFeeBps: feeBps.toString(),
maxAccounts: maxAccounts.toString(),
swapMode,
onlyDirectRoutes: `${onlyDirectRoutes}`,
@ -122,7 +120,6 @@ export const handleGetRoutes = async (
amount = 0,
slippage = 50,
swapMode = 'ExactIn',
feeBps = 1,
wallet: string | undefined,
mangoAccount: MangoAccount | undefined,
mode: SwapModes = 'ALL',
@ -168,7 +165,6 @@ export const handleGetRoutes = async (
amount,
slippage,
swapMode,
feeBps,
jupiterOnlyDirectRoutes,
maxAccounts,
)
@ -232,7 +228,6 @@ const useQuoteRoutes = ({
nativeAmount.toNumber(),
slippage,
swapMode,
1,
wallet,
mangoAccount,
mode,

View File

@ -131,7 +131,7 @@ export const getTokenInMax = (
outputBank.getRemainingDepositLimit()!,
outputBank.mintDecimals,
) *
outputBank.uiPrice >=
outputBank.uiPrice <=
inputBank.uiPrice * rawMaxUiAmountWithBorrow,
}
}

View File

@ -50,9 +50,7 @@ const ActionPanel = ({ bank }: { bank: Bank }) => {
<h2 className="mb-4 text-lg">Your {bank?.name}</h2>
<div className="border-b border-th-bkg-4">
<div className="flex justify-between border-t border-th-bkg-4 py-3">
<p>
{bank.name} {t('balance')}
</p>
<p>{t('balance')}</p>
<p className="font-mono text-th-fgd-2">
{mangoAccount ? (
<FormatNumericValue

View File

@ -24,12 +24,11 @@
"dependencies": {
"@blockworks-foundation/mango-feeds": "0.1.7",
"@blockworks-foundation/mango-mints-redemption": "^0.0.10",
"@blockworks-foundation/mango-v4": "0.21.27",
"@blockworks-foundation/mango-v4": "0.21.29",
"@blockworks-foundation/mango-v4-settings": "0.4.10",
"@blockworks-foundation/mangolana": "0.0.14",
"@headlessui/react": "1.6.6",
"@heroicons/react": "2.0.18",
"@jup-ag/referral-sdk": "0.1.5",
"@metaplex-foundation/js": "0.19.4",
"@orca-so/whirlpools-sdk": "0.11.7",
"@project-serum/anchor": "0.25.0",

View File

@ -192,10 +192,6 @@ export const CUSTOM_TOKEN_ICONS: { [key: string]: boolean } = {
export const DEFAULT_FAVORITE_MKTS = ['SOL-PERP', 'ETH-PERP', 'BTC-PERP']
export const JUPITER_REFERRAL_PK = new PublicKey(
'EV4qhLE2yPKdUPdQ74EWJUn21xT3eGQxG3DRR1g9NNFc',
)
export const WHITE_LIST_API = 'https://api.mngo.cloud/whitelist/v1/'
export const DAILY_SECONDS = 86400
export const DAILY_MILLISECONDS = 86400000

View File

@ -11,6 +11,7 @@ import {
Transaction,
TransactionInstruction,
} from '@solana/web3.js'
import { IDL } from '@blockworks-foundation/mango-v4'
export type TransactionNotification = {
type: 'success' | 'info' | 'error' | 'confirm'
@ -70,15 +71,16 @@ export function notify(newNotification: {
...newNotification,
}
const parsedNotif = enrichError(newNotif)
if (
!newNotif.txid ||
!parsedNotif.txid ||
!notifications.find(
(n) => n.txid == newNotif.txid && n.type == newNotif.type,
(n) => n.txid == parsedNotif.txid && n.type == parsedNotif.type,
)
) {
setMangoStore((state) => {
state.transactionNotificationIdCounter = newId
state.transactionNotifications = [...notifications, newNotif]
state.transactionNotifications = [...notifications, parsedNotif]
})
}
}
@ -198,3 +200,28 @@ export const createLedgerMessage = async (
}
setCookie(payload.address, token)
}
function enrichError(
unparsedNotification: TransactionNotification,
): TransactionNotification {
const notification = { ...unparsedNotification }
if (
notification.txid !== null &&
notification.type == 'error' &&
notification.description
) {
try {
const errorObject = JSON.parse(notification.description)
const errorCode = errorObject.value.err.InstructionError[1].Custom
if (errorCode - 6000 >= 0) {
const idlError = IDL.errors[errorCode - 6000]
notification.description = `Error Code ${idlError.code}: ${idlError.name} (${idlError.msg})`
} else if (errorCode === 1) {
notification.description = 'Error Code 0x1: Insufficient funds'
}
} catch (e) {
console.log('error while parsing txn error: ', e)
}
}
return notification
}

View File

@ -350,10 +350,10 @@
bn.js "^5.2.1"
eslint-config-prettier "^9.0.0"
"@blockworks-foundation/mango-v4@0.21.27":
version "0.21.27"
resolved "https://registry.yarnpkg.com/@blockworks-foundation/mango-v4/-/mango-v4-0.21.27.tgz#1abb4ab908e6f9ae69db47b54dc7d6188e321cb1"
integrity sha512-lBS5bGkfokNvS6Q+rXjHFnfDVpJ8tmaV4WxyDTz6JYnGDQtui2JimpZ78sO4R7cqiaH6QEUSIPykpsA4dLaccg==
"@blockworks-foundation/mango-v4@0.21.29":
version "0.21.29"
resolved "https://registry.yarnpkg.com/@blockworks-foundation/mango-v4/-/mango-v4-0.21.29.tgz#4ff5f6c7efed7daa6f34ac2779a3fd5785a5566e"
integrity sha512-gu+U55g52ttLu+44z66+5NDhLYaCGujjUjQm1/jVHbE4iXwgQoBCxY/QD6a0rZVR9tJYs+epoCL3KK9q0AUqCg==
dependencies:
"@blockworks-foundation/mango-v4-settings" "0.4.10"
"@blockworks-foundation/mangolana" "0.0.14"
@ -413,7 +413,7 @@
resolved "https://registry.yarnpkg.com/@contentful/rich-text-types/-/rich-text-types-16.3.4.tgz#c5fc9c834dde03d4c4ee189900d304ce1888a74b"
integrity sha512-PyVSrQa5j1hO4grgA0Ivo/taiOvW0uFN79JB5JkTG8U7DnWGI7Ap2As6zN6/E6YvDqb7w2cYRMSGSQ3qfxu8HQ==
"@coral-xyz/anchor@0.28.1-beta.2", "@coral-xyz/anchor@^0.26.0", "@coral-xyz/anchor@^0.27.0", "@coral-xyz/anchor@^0.28.0", "@coral-xyz/anchor@^0.28.1-beta.2", "@coral-xyz/anchor@~0.27.0":
"@coral-xyz/anchor@^0.26.0", "@coral-xyz/anchor@^0.27.0", "@coral-xyz/anchor@^0.28.0", "@coral-xyz/anchor@^0.28.1-beta.2", "@coral-xyz/anchor@~0.27.0":
version "0.27.0"
resolved "https://registry.yarnpkg.com/@coral-xyz/anchor/-/anchor-0.27.0.tgz#621e5ef123d05811b97e49973b4ed7ede27c705c"
integrity sha512-+P/vPdORawvg3A9Wj02iquxb4T0C5m4P6aZBVYysKl4Amk+r6aMPZkUhilBkD6E4Nuxnoajv3CFykUfkGE0n5g==
@ -1249,16 +1249,6 @@
"@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14"
"@jup-ag/referral-sdk@0.1.5":
version "0.1.5"
resolved "https://registry.yarnpkg.com/@jup-ag/referral-sdk/-/referral-sdk-0.1.5.tgz#02a8bc901154659e75a5f31ae9a3e3edd28cd6cd"
integrity sha512-0R/NuBkIj2otpLnatacZqIwVAwL+OIheSlT+a2atAaNuf2WceL4lKZ/EZWm1AVTFhmFd/07HHN9PJ2fma9AMPA==
dependencies:
"@coral-xyz/anchor" "0.28.1-beta.2"
"@solana/spl-token" "0.3.8"
"@solana/web3.js" "^1.77.3"
lodash "^4.17.21"
"@keystonehq/bc-ur-registry-sol@^0.3.1":
version "0.3.1"
resolved "https://registry.yarnpkg.com/@keystonehq/bc-ur-registry-sol/-/bc-ur-registry-sol-0.3.1.tgz#5319c7c4a22cc83bbacfa6fe09aaa6fb21363f24"
@ -2344,15 +2334,6 @@
"@solana/buffer-layout-utils" "^0.2.0"
buffer "^6.0.3"
"@solana/spl-token@0.3.8":
version "0.3.8"
resolved "https://registry.yarnpkg.com/@solana/spl-token/-/spl-token-0.3.8.tgz#8e9515ea876e40a4cc1040af865f61fc51d27edf"
integrity sha512-ogwGDcunP9Lkj+9CODOWMiVJEdRtqHAtX2rWF62KxnnSWtMZtV9rDhTrZFshiyJmxDnRL/1nKE1yJHg4jjs3gg==
dependencies:
"@solana/buffer-layout" "^4.0.0"
"@solana/buffer-layout-utils" "^0.2.0"
buffer "^6.0.3"
"@solana/spl-token@^0.1.6", "@solana/spl-token@^0.1.8":
version "0.1.8"
resolved "https://registry.yarnpkg.com/@solana/spl-token/-/spl-token-0.1.8.tgz#f06e746341ef8d04165e21fc7f555492a2a0faa6"
@ -2769,7 +2750,7 @@
"@wallet-standard/app" "^1.0.1"
"@wallet-standard/base" "^1.0.1"
"@solana/web3.js@^1.17.0", "@solana/web3.js@^1.21.0", "@solana/web3.js@^1.22.0", "@solana/web3.js@^1.32.0", "@solana/web3.js@^1.36.0", "@solana/web3.js@^1.50.1", "@solana/web3.js@^1.56.2", "@solana/web3.js@^1.63.1", "@solana/web3.js@^1.66.2", "@solana/web3.js@^1.68.0", "@solana/web3.js@^1.75.0", "@solana/web3.js@^1.77.3", "@solana/web3.js@^1.78.2", "@solana/web3.js@^1.78.3", "@solana/web3.js@^1.87.6", "@solana/web3.js@^1.88.0":
"@solana/web3.js@^1.17.0", "@solana/web3.js@^1.21.0", "@solana/web3.js@^1.22.0", "@solana/web3.js@^1.32.0", "@solana/web3.js@^1.36.0", "@solana/web3.js@^1.50.1", "@solana/web3.js@^1.56.2", "@solana/web3.js@^1.63.1", "@solana/web3.js@^1.66.2", "@solana/web3.js@^1.68.0", "@solana/web3.js@^1.75.0", "@solana/web3.js@^1.78.2", "@solana/web3.js@^1.78.3", "@solana/web3.js@^1.87.6", "@solana/web3.js@^1.88.0":
version "1.89.1"
resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.89.1.tgz#52df6820f2d088c4558aa359af40580a03d10ec9"
integrity sha512-t9TTLtPQxtQB3SAf/5E8xPXfVDsC6WGOsgKY02l2cbe0HLymT7ynE8Hu48Lk5qynHCquj6nhISfEHcjMkYpu/A==