Merge pull request #299 from blockworks-foundation/lou/jup-max-accounts
maxAccounts is dynamic based on health for Jupiter swaps
This commit is contained in:
commit
6c1f827ee8
|
@ -251,6 +251,7 @@ const ListToken = ({ goBack }: { goBack: () => void }) => {
|
|||
mode,
|
||||
FEE,
|
||||
walletForCheck,
|
||||
undefined, // mangoAccount
|
||||
'JUPITER',
|
||||
onlyDirect,
|
||||
)
|
||||
|
|
|
@ -80,6 +80,7 @@ const MarketSwapForm = ({
|
|||
const [debouncedAmountIn] = useDebounce(amountInFormValue, 300)
|
||||
const [debouncedAmountOut] = useDebounce(amountOutFormValue, 300)
|
||||
const { connected, publicKey } = useWallet()
|
||||
const { mangoAccount } = useMangoAccount()
|
||||
const { bestRoute } = useQuoteRoutes({
|
||||
inputMint: inputBank?.mint.toString() || USDC_MINT,
|
||||
outputMint: outputBank?.mint.toString() || MANGO_MINT,
|
||||
|
@ -87,6 +88,7 @@ const MarketSwapForm = ({
|
|||
slippage,
|
||||
swapMode,
|
||||
wallet: publicKey?.toBase58(),
|
||||
mangoAccount,
|
||||
})
|
||||
const { ipAllowed, ipCountry } = useIpAddress()
|
||||
|
||||
|
|
|
@ -152,7 +152,6 @@ export const fetchJupiterTransaction = async (
|
|||
// This is the ATA account for the output token where the fee will be sent to. If you are swapping from SOL->USDC then this would be the USDC ATA you want to collect the fee.
|
||||
// feeAccount: 'fee_account_public_key',
|
||||
slippageBps: Math.ceil(slippage * 100),
|
||||
maxAccounts: 50,
|
||||
}),
|
||||
})
|
||||
).json()
|
||||
|
|
|
@ -70,6 +70,7 @@ const WalletSwapForm = ({ setShowTokenSelect }: WalletSwapFormProps) => {
|
|||
slippage,
|
||||
swapMode,
|
||||
wallet: publicKey?.toBase58(),
|
||||
mangoAccount: undefined,
|
||||
mode: 'JUPITER',
|
||||
})
|
||||
const { ipAllowed, ipCountry } = useIpAddress()
|
||||
|
|
|
@ -8,6 +8,7 @@ import useJupiterSwapData from './useJupiterSwapData'
|
|||
import useDebounce from '@components/shared/useDebounce'
|
||||
import { useMemo } from 'react'
|
||||
import { JUPITER_V6_QUOTE_API_MAINNET } from 'utils/constants'
|
||||
import { MangoAccount } from '@blockworks-foundation/mango-v4'
|
||||
|
||||
type SwapModes = 'ALL' | 'JUPITER' | 'MANGO'
|
||||
|
||||
|
@ -18,6 +19,7 @@ type useQuoteRoutesPropTypes = {
|
|||
slippage: number
|
||||
swapMode: string
|
||||
wallet: string | undefined
|
||||
mangoAccount: MangoAccount | undefined
|
||||
mode?: SwapModes
|
||||
enabled?: () => boolean
|
||||
}
|
||||
|
@ -30,7 +32,7 @@ const fetchJupiterRoute = async (
|
|||
swapMode = 'ExactIn',
|
||||
feeBps = 0,
|
||||
onlyDirectRoutes = true,
|
||||
maxAccounts = 50,
|
||||
maxAccounts = 64,
|
||||
) => {
|
||||
{
|
||||
const paramsString = new URLSearchParams({
|
||||
|
@ -119,12 +121,27 @@ export const handleGetRoutes = async (
|
|||
swapMode = 'ExactIn',
|
||||
feeBps = 0,
|
||||
wallet: string | undefined,
|
||||
mangoAccount: MangoAccount | undefined,
|
||||
mode: SwapModes = 'ALL',
|
||||
jupiterOnlyDirectRoutes = false,
|
||||
) => {
|
||||
try {
|
||||
wallet ||= PublicKey.default.toBase58()
|
||||
|
||||
let maxAccounts: number
|
||||
if (!mangoAccount) {
|
||||
maxAccounts = 64
|
||||
} else {
|
||||
// TODO: replace with client method
|
||||
const totalSlots =
|
||||
mangoAccount.tokensActive().length +
|
||||
mangoAccount.serum3Active().length +
|
||||
mangoAccount.tokenConditionalSwapsActive().length +
|
||||
mangoAccount.perpActive().length +
|
||||
mangoAccount.perpOrdersActive().length
|
||||
maxAccounts = 56 - 2 * totalSlots
|
||||
}
|
||||
|
||||
const routes = []
|
||||
|
||||
// FIXME: Disable for now, mango router needs to use ALTs
|
||||
|
@ -150,6 +167,7 @@ export const handleGetRoutes = async (
|
|||
swapMode,
|
||||
feeBps,
|
||||
jupiterOnlyDirectRoutes,
|
||||
maxAccounts,
|
||||
)
|
||||
routes.push(jupiterRoute)
|
||||
}
|
||||
|
@ -185,6 +203,7 @@ const useQuoteRoutes = ({
|
|||
slippage,
|
||||
swapMode,
|
||||
wallet,
|
||||
mangoAccount,
|
||||
mode = 'ALL',
|
||||
enabled,
|
||||
}: useQuoteRoutesPropTypes) => {
|
||||
|
@ -222,6 +241,7 @@ const useQuoteRoutes = ({
|
|||
swapMode,
|
||||
0,
|
||||
wallet,
|
||||
mangoAccount,
|
||||
mode,
|
||||
),
|
||||
{
|
||||
|
|
|
@ -48,6 +48,7 @@ import { useTokenMax } from '@components/swap/useTokenMax'
|
|||
import SheenLoader from '@components/shared/SheenLoader'
|
||||
import { fetchJupiterTransaction } from '@components/swap/SwapReviewRouteInfo'
|
||||
import MaxMarketTradeAmount from './MaxMarketTradeAmount'
|
||||
import useMangoAccount from 'hooks/useMangoAccount'
|
||||
|
||||
const set = mangoStore.getState().set
|
||||
|
||||
|
@ -66,6 +67,7 @@ export default function SpotMarketOrderSwapForm() {
|
|||
const [placingOrder, setPlacingOrder] = useState(false)
|
||||
const { ipAllowed, ipCountry } = useIpAddress()
|
||||
const { connected, publicKey, connect } = useWallet()
|
||||
const { mangoAccount } = useMangoAccount()
|
||||
const [swapFormSizeUi] = useLocalStorageState(SIZE_INPUT_UI_KEY, 'slider')
|
||||
const [savedCheckboxSettings, setSavedCheckboxSettings] =
|
||||
useLocalStorageState(TRADE_CHECKBOXES_KEY, DEFAULT_CHECKBOX_SETTINGS)
|
||||
|
@ -207,6 +209,7 @@ export default function SpotMarketOrderSwapForm() {
|
|||
slippage,
|
||||
swapMode: 'ExactIn',
|
||||
wallet: publicKey?.toBase58(),
|
||||
mangoAccount,
|
||||
mode: 'JUPITER',
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue