JLP Update

This commit is contained in:
Finn 2024-02-20 12:59:49 +00:00
parent 4eecea8bac
commit ad7bbcf520
12 changed files with 205 additions and 93 deletions

View File

@ -6,6 +6,7 @@ import TransactionHistory from './TransactionHistory'
import mangoStore, { ActiveTab } from '@store/mangoStore'
import { useCallback, useEffect } from 'react'
import { BOOST_ACCOUNT_PREFIX } from 'utils/constants'
import useMangoAccount from 'hooks/useMangoAccount'
const set = mangoStore.getState().set
@ -27,16 +28,14 @@ const HomePage = () => {
ma.name.toLowerCase() ===
`${(BOOST_ACCOUNT_PREFIX + selectedToken).toLowerCase()}`,
)
console.log(
'selectedMangoAccount',
(BOOST_ACCOUNT_PREFIX + selectedToken).toLowerCase(),
selectedMangoAccount,
)
set((s) => {
s.mangoAccount.current = selectedMangoAccount
})
}, [selectedToken])
return (
<>
<div className="mb-6 grid grid-cols-3">

View File

@ -61,6 +61,7 @@ export const walletBalanceForToken = (
: null
}
return {
maxAmount: walletToken ? walletToken.uiAmount : 0,
maxDecimals: bank?.mintDecimals || 6,
@ -103,9 +104,17 @@ function StakeForm({ token: selectedToken }: StakeFormProps) {
}, [selectedToken, group])
const borrowBank = useMemo(() => {
return group?.banksMapByName.get('SOL')?.[0]
return group?.banksMapByName.get('USDC')?.[0]
}, [group])
const liquidationPrice = useMemo(() => {
const borrowMaintLiabWeight = borrowBank?.maintLiabWeight
const stakeMaintAssetWeight = stakeBank?.maintAssetWeight
const price = Number(stakeBank?.uiPrice) * (Number(borrowMaintLiabWeight) / Number(stakeMaintAssetWeight)) * (1 - (1 / leverage))
return price
}, [stakeBank, borrowBank, leverage])
const tokenPositionsFull = useMemo(() => {
if (!stakeBank || !usedTokens.length || !totalTokens.length) return false
const hasTokenPosition = usedTokens.find(
@ -117,6 +126,7 @@ function StakeForm({ token: selectedToken }: StakeFormProps) {
const { connected, publicKey } = useWallet()
const walletTokens = mangoStore((s) => s.wallet.tokens)
const tokenMax = useMemo(() => {
return walletBalanceForToken(walletTokens, selectedToken)
}, [walletTokens, selectedToken])
@ -127,13 +137,10 @@ function StakeForm({ token: selectedToken }: StakeFormProps) {
}, [tokenMax])
const amountToBorrow = useMemo(() => {
const solPrice = borrowBank?.uiPrice
const borrowPrice = borrowBank?.uiPrice
const stakePrice = stakeBank?.uiPrice
if (!solPrice || !stakePrice || !Number(inputAmount)) return 0
const priceDifference = (stakePrice - solPrice) / solPrice
const borrowAmount =
(1 + priceDifference) * Number(inputAmount) * Math.min(leverage - 1, 1)
if (!borrowPrice || !stakePrice || !Number(inputAmount)) return 0
const borrowAmount = stakeBank?.uiPrice * Number(inputAmount) * (leverage - 1)
return borrowAmount
}, [leverage, borrowBank, stakeBank, inputAmount])
@ -151,7 +158,7 @@ function StakeForm({ token: selectedToken }: StakeFormProps) {
const actions = mangoStore.getState().actions
// const mangoAccounts = mangoStore.getState().mangoAccounts
const mangoAccount = mangoStore.getState().mangoAccount.current
if (!group || !stakeBank || !publicKey) return
set((state) => {
@ -209,12 +216,13 @@ function StakeForm({ token: selectedToken }: StakeFormProps) {
const showInsufficientBalance =
tokenMax.maxAmount < Number(inputAmount) ||
(selectedToken === 'SOL' && maxSolDeposit <= 0)
(selectedToken === 'USDC' && maxSolDeposit <= 0)
const changeLeverage = useCallback((v: number) => {
setLeverage(v * 1)
}, [])
useEffect(() => {
const group = mangoStore.getState().group
set((state) => {
@ -301,9 +309,8 @@ function StakeForm({ token: selectedToken }: StakeFormProps) {
{({ open }) => (
<>
<Disclosure.Button
className={`w-full rounded-xl border-2 border-th-bkg-3 px-4 py-3 text-left focus:outline-none ${
open ? 'rounded-b-none border-b-0' : ''
}`}
className={`w-full rounded-xl border-2 border-th-bkg-3 px-4 py-3 text-left focus:outline-none ${open ? 'rounded-b-none border-b-0' : ''
}`}
>
<div className="flex items-center justify-between">
<p className="font-medium">Est. Net APY</p>
@ -312,8 +319,8 @@ function StakeForm({ token: selectedToken }: StakeFormProps) {
{estimatedNetAPY >= 0
? '+'
: estimatedNetAPY === 0
? ''
: '-'}
? ''
: '-'}
<FormatNumericValue
value={estimatedNetAPY}
decimals={2}
@ -321,9 +328,8 @@ function StakeForm({ token: selectedToken }: StakeFormProps) {
%
</span>
<ChevronDownIcon
className={`${
open ? 'rotate-180' : 'rotate-360'
} h-6 w-6 shrink-0 text-th-fgd-1`}
className={`${open ? 'rotate-180' : 'rotate-360'
} h-6 w-6 shrink-0 text-th-fgd-1`}
/>
</div>
</div>
@ -347,11 +353,10 @@ function StakeForm({ token: selectedToken }: StakeFormProps) {
{formatTokenSymbol(selectedToken)} Deposit Rate
</p>
<span
className={`font-bold ${
stakeBankDepositRate > 0.01
? 'text-th-success'
: 'text-th-bkg-4'
}`}
className={`font-bold ${stakeBankDepositRate > 0.01
? 'text-th-success'
: 'text-th-bkg-4'
}`}
>
{stakeBankDepositRate > 0.01 ? '+' : ''}
<FormatNumericValue
@ -366,11 +371,10 @@ function StakeForm({ token: selectedToken }: StakeFormProps) {
<div className="flex justify-between">
<p className="text-th-fgd-4">{`${borrowBank.name} Borrow Rate`}</p>
<span
className={`font-bold ${
borrowBankBorrowRate > 0.01
? 'text-th-error'
: 'text-th-bkg-4'
}`}
className={`font-bold ${borrowBankBorrowRate > 0.01
? 'text-th-error'
: 'text-th-bkg-4'
}`}
>
-
<FormatNumericValue
@ -383,11 +387,10 @@ function StakeForm({ token: selectedToken }: StakeFormProps) {
<div className="flex justify-between">
<p className="text-th-fgd-4">{`${borrowBank.name} Borrowed`}</p>
<span
className={`font-bold ${
amountToBorrow > 0.001
? 'text-th-fgd-1'
: 'text-th-bkg-4'
}`}
className={`font-bold ${amountToBorrow > 0.001
? 'text-th-fgd-1'
: 'text-th-bkg-4'
}`}
>
<FormatNumericValue
value={amountToBorrow}
@ -399,6 +402,54 @@ function StakeForm({ token: selectedToken }: StakeFormProps) {
</span>
</span>
</div>
<div className="flex justify-between">
<p className="text-th-fgd-4">{`${stakeBank.name} Position`}</p>
<span
className={`font-bold ${amountToBorrow > 0.001
? 'text-th-fgd-1'
: 'text-th-bkg-4'
}`}
>
<FormatNumericValue
value={leverage * Number(inputAmount)}
decimals={3}
/>
<span className="font-body text-th-fgd-4">
{' '}
{stakeBank.name}
{' '}
</span>
<span className="font-body text-th-fgd-4">
{' '}
(
<FormatNumericValue
value={leverage * Number(inputAmount) * stakeBank?.uiPrice}
decimals={3}
/>
{' '}
{borrowBank.name})
</span>
</span>
</div>
<div className="flex justify-between">
<p className="text-th-fgd-4">{`Liquidation Price`}</p>
<span
className={`font-bold ${amountToBorrow > 0.001
? 'text-th-fgd-1'
: 'text-th-bkg-4'
}`}
>
<FormatNumericValue
value={liquidationPrice}
decimals={5}
/>
<span className="font-body text-th-fgd-4">
{' '}
{borrowBank.name}
</span>
</span>
</div>
</>
) : null}
</Disclosure.Panel>

View File

@ -84,8 +84,8 @@ function UnstakeForm({ token: selectedToken }: UnstakeFormProps) {
return group?.banksMapByName.get(selectedToken)?.[0]
}, [selectedToken, group])
const solBank = useMemo(() => {
return group?.banksMapByName.get('SOL')?.[0]
const borrowBank = useMemo(() => {
return group?.banksMapByName.get('USDC')?.[0]
}, [group])
const tokenPositionsFull = useMemo(() => {
@ -137,10 +137,10 @@ function UnstakeForm({ token: selectedToken }: UnstakeFormProps) {
setRefreshingWalletTokens(false)
}, [publicKey])
const solBorrowed = useMemo(() => {
if (!solBank || !mangoAccount) return 0.0
return mangoAccount.getTokenBalanceUi(solBank)
}, [solBank, mangoAccount])
const borrowed = useMemo(() => {
if (!borrowBank || !mangoAccount) return 0.0
return mangoAccount.getTokenBalanceUi(borrowBank)
}, [borrowBank, mangoAccount])
const handleWithdraw = useCallback(async () => {
const client = mangoStore.getState().client
@ -148,16 +148,16 @@ function UnstakeForm({ token: selectedToken }: UnstakeFormProps) {
const actions = mangoStore.getState().actions
let mangoAccount = mangoStore.getState().mangoAccount.current
if (!group || !stakeBank || !solBank || !publicKey || !mangoAccount) return
if (!group || !stakeBank || !borrowBank || !publicKey || !mangoAccount) return
setSubmitting(true)
try {
if (mangoAccount.getTokenBalanceUi(solBank) < 0) {
if (mangoAccount.getTokenBalanceUi(borrowBank) < 0) {
notify({
title: 'Sending transaction 1 of 2',
type: 'info',
})
console.log('unstake and swap', mangoAccount.getTokenBalanceUi(solBank))
console.log('unstake and swap', mangoAccount.getTokenBalanceUi(borrowBank))
const { signature: tx } = await unstakeAndSwap(
client,
@ -291,7 +291,7 @@ function UnstakeForm({ token: selectedToken }: UnstakeFormProps) {
/>
</div>
</div>
{stakeBank && solBank ? (
{stakeBank && borrowBank ? (
<div className="pt-8">
<Disclosure>
{({ open }) => (
@ -330,16 +330,16 @@ function UnstakeForm({ token: selectedToken }: UnstakeFormProps) {
</div>
<div className="flex justify-between">
<p className="text-th-fgd-4">SOL borrowed</p>
{solBank ? (
{borrowBank ? (
<span
className={`font-bold ${
solBorrowed > 0.001
borrowed > 0.001
? 'text-th-fgd-1'
: 'text-th-bkg-4'
}`}
>
<FormatNumericValue
value={solBorrowed}
value={borrowed}
decimals={3}
/>
</span>

View File

@ -9,6 +9,7 @@ import useLeverageMax from './useLeverageMax'
export default function useBankRates(selectedToken: string, leverage: number) {
const { data: stakeRates } = useStakeRates()
const { group } = useMangoGroup()
// const estimatedMaxAPY = mangoStore((s) => s.estimatedMaxAPY.current)
const leverageMax = useLeverageMax(selectedToken)
@ -17,7 +18,7 @@ export default function useBankRates(selectedToken: string, leverage: number) {
}, [selectedToken, group])
const borrowBank = useMemo(() => {
return group?.banksMapByName.get('SOL')?.[0]
return group?.banksMapByName.get('USDC')?.[0]
}, [group])
const stakeBankDepositRate = useMemo(() => {

View File

@ -10,26 +10,22 @@ export default function useLeverageMax(selectedToken: string) {
}, [selectedToken, group])
const borrowBank = useMemo(() => {
return group?.banksMapByName.get('SOL')?.[0]
return group?.banksMapByName.get('USDC')?.[0]
}, [group])
const leverageMax = useMemo(() => {
if (!stakeBank || !borrowBank) return 0
const borrowInitLiabWeight = borrowBank.scaledInitLiabWeight(
borrowBank.price,
)
const stakeInitAssetWeight = stakeBank.scaledInitAssetWeight(
stakeBank.price,
)
const borrowInitLiabWeight = borrowBank.initLiabWeight
const stakeInitAssetWeight = stakeBank.initAssetWeight
if (!borrowInitLiabWeight || !stakeInitAssetWeight) return 1
const x = stakeInitAssetWeight.toNumber() / borrowInitLiabWeight.toNumber()
const conversionRate = borrowBank.uiPrice / stakeBank.uiPrice
const leverageFactor = 1 / (1 - x)
const y = 1 - conversionRate * stakeInitAssetWeight.toNumber()
const max = floorToDecimal(1 + (x / y) * 0.9, 1).toNumber()
const max = floorToDecimal(leverageFactor, 1).toNumber()
return max
}, [stakeBank, borrowBank])

View File

@ -7,10 +7,9 @@ export default function useStakeAccounts(): {
stakeAccounts: MangoAccount[] | undefined
} {
const mangoAccounts = mangoStore((s) => s.mangoAccounts)
const stakeAccounts = useMemo(() => {
return mangoAccounts.filter((ma) =>
ma.name.includes(`${BOOST_ACCOUNT_PREFIX}`),
ma.name.includes(`${BOOST_ACCOUNT_PREFIX.toLowerCase()}`),
)
}, [mangoAccounts])

View File

@ -15,13 +15,18 @@ const fetchRates = async () => {
fetchAndParsePricesCsv(DATA_SOURCE.LIDO_CSV),
])
const jlpPricesData = await (await fetch(`https://api.coingecko.com/api/v3/coins/jupiter-perpetuals-liquidity-provider-token/market_chart?vs_currency=usd&days=30`)).json();
const jlpPricesPrice = jlpPricesData.prices.map((priceAndTime: Array<Number>) => priceAndTime[1])
// may be null if the price range cannot be calculated
const msolRange = getPriceRangeFromPeriod(msolPrices, PERIOD.DAYS_30)
const jitoRange = getPriceRangeFromPeriod(jitoPrices, PERIOD.DAYS_30)
const bsolRange = getPriceRangeFromPeriod(bsolPrices, PERIOD.DAYS_30)
const lidoRange = getPriceRangeFromPeriod(lidoPrices, PERIOD.DAYS_30)
const jlpRange = getPriceRangeFromPeriod(lidoPrices, PERIOD.DAYS_30)
const rateData: Record<string, number> = {}
rateData.jlp = 12 * (jlpPricesPrice[jlpPricesPrice.length - 1] - jlpPricesPrice[0]) / jlpPricesPrice[0]
if (msolRange) {
rateData.msol = calcYield(msolRange)?.apy

View File

@ -8,7 +8,7 @@ const nextConfig = {
appDir: false,
},
images: {
domains: ['raw.githubusercontent.com', 'arweave.net', 'www.dual.finance'],
domains: ['raw.githubusercontent.com', 'arweave.net', 'www.dual.finance', 'static.jup.ag'],
},
reactStrictMode: true,
//proxy for openserum api cors

62
public/icons/jlp.svg Normal file
View File

@ -0,0 +1,62 @@
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_159_25)">
<path d="M16 32C24.8366 32 32 24.8366 32 16C32 7.16344 24.8366 0 16 0C7.16344 0 0 7.16344 0 16C0 24.8366 7.16344 32 16 32Z" fill="black"/>
<mask id="mask0_159_25" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="0" y="0" width="32" height="32">
<path d="M16 32C24.8366 32 32 24.8366 32 16C32 7.16344 24.8366 0 16 0C7.16344 0 0 7.16344 0 16C0 24.8366 7.16344 32 16 32Z" fill="black"/>
</mask>
<g mask="url(#mask0_159_25)">
<g filter="url(#filter0_d_159_25)">
<path d="M13.2125 32.8988C10.0045 31.0184 6.53232 30.5392 4.04785 31.3858C4.2877 32.1855 4.60401 32.9599 4.99234 33.698C7.15091 33.6475 9.50771 34.239 11.7007 35.5241C13.8937 36.8091 15.571 38.5827 16.5974 40.5C17.4257 40.4744 18.2496 40.3679 19.0575 40.1822C18.5552 37.5858 16.4198 34.7796 13.2125 32.8988Z" fill="url(#paint0_linear_159_25)"/>
<path d="M28.4998 25.2663C28.092 23.5925 27.3539 22.0188 26.3299 20.6391C25.3058 19.2594 24.0166 18.1021 22.5394 17.2362C21.0622 16.3703 19.4272 15.8137 17.732 15.5995C16.0368 15.3852 14.3162 15.5179 12.673 15.9894C15.4182 16.3284 18.4654 17.3681 21.4538 19.1197C24.4422 20.8713 26.849 23.0266 28.4998 25.2663Z" fill="url(#paint1_linear_159_25)"/>
<path d="M24.5063 31.4049C23.1011 29.0505 20.6939 26.7959 17.7286 25.058C14.7633 23.3199 11.6304 22.3272 8.90951 22.2615C6.51576 22.2043 4.71919 22.9064 3.98174 24.1873C3.97755 24.1948 3.97167 24.202 3.96705 24.2097C3.90069 24.4499 3.84358 24.6905 3.7915 24.9321C4.82124 24.522 6.01433 24.2936 7.34098 24.2681C10.2912 24.2123 13.5928 25.1643 16.6397 26.9502C19.6864 28.7361 22.1436 31.1592 23.5563 33.7717C24.1896 34.9488 24.5848 36.1076 24.7414 37.2147C24.9237 37.0503 25.1026 36.8804 25.2761 36.7038C25.2807 36.6957 25.2836 36.6872 25.2882 36.6788C26.0257 35.3966 25.7405 33.4747 24.5063 31.4049Z" fill="url(#paint2_linear_159_25)"/>
<path d="M15.4721 28.9754C10.9311 26.3138 5.91307 25.8968 3.5 27.7543C3.50474 28.3357 3.5488 28.9161 3.63187 29.4915C4.34171 29.2744 5.0733 29.1377 5.81312 29.0839C8.50966 28.8792 11.4825 29.6373 14.1804 31.2193C16.8781 32.8014 19.0048 35.0327 20.1647 37.4955C20.4853 38.1703 20.7299 38.8792 20.8937 39.609C21.4304 39.3967 21.9523 39.148 22.4556 38.8645C22.8596 35.8291 20.0144 31.6375 15.4721 28.9754Z" fill="url(#paint3_linear_159_25)"/>
<path d="M26.8418 27.4641C25.4207 25.1122 22.9925 22.8513 20.0061 21.1019C17.0199 19.3524 13.8748 18.344 11.1451 18.2631C9.06421 18.2025 7.45242 18.7114 6.6167 19.6727C10.0868 19.0796 14.6639 20.0765 19.1003 22.6768C23.5368 25.277 26.6638 28.7954 27.8707 32.1303C28.2844 30.9223 27.9245 29.2577 26.8418 27.4641Z" fill="url(#paint4_linear_159_25)"/>
</g>
<path d="M16.9938 13.375V4.64773H20.437C21.0989 4.64773 21.6628 4.77415 22.1287 5.02699C22.5946 5.27699 22.9497 5.625 23.1941 6.07102C23.4412 6.5142 23.5648 7.02557 23.5648 7.60511C23.5648 8.18466 23.4398 8.69602 23.1898 9.1392C22.9398 9.58239 22.5776 9.92756 22.1031 10.1747C21.6316 10.4219 21.0605 10.5455 20.3901 10.5455H18.1955V9.06676H20.0918C20.4469 9.06676 20.7395 9.00568 20.9696 8.88352C21.2026 8.75852 21.3759 8.58665 21.4895 8.3679C21.606 8.14631 21.6642 7.89205 21.6642 7.60511C21.6642 7.31534 21.606 7.0625 21.4895 6.84659C21.3759 6.62784 21.2026 6.45881 20.9696 6.33949C20.7367 6.21733 20.4412 6.15625 20.0833 6.15625H18.8389V13.375H16.9938Z" fill="url(#paint5_linear_159_25)"/>
<path d="M9.93518 13.375V4.64773H11.7804V11.8537H15.5218V13.375H9.93518Z" fill="url(#paint6_linear_159_25)"/>
</g>
</g>
<defs>
<filter id="filter0_d_159_25" x="-19.2448" y="-4.97031" width="70.4894" height="70.4896" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
<feOffset dy="2.27449"/>
<feGaussianBlur stdDeviation="11.3724"/>
<feComposite in2="hardAlpha" operator="out"/>
<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0"/>
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_159_25"/>
<feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow_159_25" result="shape"/>
</filter>
<linearGradient id="paint0_linear_159_25" x1="20.1484" y1="20.5781" x2="8.50923" y2="40.4102" gradientUnits="userSpaceOnUse">
<stop offset="0.0001" stop-color="#C7F284"/>
<stop offset="1" stop-color="#00BEF0"/>
</linearGradient>
<linearGradient id="paint1_linear_159_25" x1="20.1483" y1="20.5781" x2="8.50917" y2="40.4102" gradientUnits="userSpaceOnUse">
<stop offset="0.0001" stop-color="#C7F284"/>
<stop offset="1" stop-color="#00BEF0"/>
</linearGradient>
<linearGradient id="paint2_linear_159_25" x1="20.1489" y1="20.5781" x2="8.50981" y2="40.4102" gradientUnits="userSpaceOnUse">
<stop offset="0.0001" stop-color="#C7F284"/>
<stop offset="1" stop-color="#00BEF0"/>
</linearGradient>
<linearGradient id="paint3_linear_159_25" x1="20.1485" y1="20.5781" x2="8.50936" y2="40.4102" gradientUnits="userSpaceOnUse">
<stop offset="0.0001" stop-color="#C7F284"/>
<stop offset="1" stop-color="#00BEF0"/>
</linearGradient>
<linearGradient id="paint4_linear_159_25" x1="20.1488" y1="20.5781" x2="8.50965" y2="40.4102" gradientUnits="userSpaceOnUse">
<stop offset="0.0001" stop-color="#C7F284"/>
<stop offset="1" stop-color="#00BEF0"/>
</linearGradient>
<linearGradient id="paint5_linear_159_25" x1="22.9191" y1="5.25" x2="14.9789" y2="7.98372" gradientUnits="userSpaceOnUse">
<stop stop-color="#C7F384"/>
<stop offset="1" stop-color="#19C5E3"/>
</linearGradient>
<linearGradient id="paint6_linear_159_25" x1="14.9728" y1="5.25" x2="8.01789" y2="7.28582" gradientUnits="userSpaceOnUse">
<stop stop-color="#C7F384"/>
<stop offset="1" stop-color="#19C5E3"/>
</linearGradient>
<clipPath id="clip0_159_25">
<rect width="32" height="32" fill="white"/>
</clipPath>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

@ -80,7 +80,8 @@ import sampleSize from 'lodash/sampleSize'
import { Token } from 'types/jupiter'
import { sleep } from 'utils'
const GROUP = new PublicKey('78b8f4cGCwmZ9ysPFMWLaLTkkaYnUjwMJYStWe5RTSSX')
const MANGO_BOOST_ID = new PublicKey('zF2vSz6V9g1YHGmfrzsY497NJzbRr84QUrPry4bLQ25')
const GROUP = new PublicKey('AKeMSYiJekyKfwCc3CUfVNDVAiqk9FfbQVMY3G7RUZUf')
const ENDPOINTS = [
{
@ -110,9 +111,9 @@ const initMangoClient = (
provider: AnchorProvider,
opts = { prioritizationFee: DEFAULT_PRIORITY_FEE },
): MangoClient => {
return MangoClient.connect(provider, CLUSTER, MANGO_V4_ID[CLUSTER], {
return MangoClient.connect(provider, CLUSTER, MANGO_BOOST_ID, {
prioritizationFee: opts.prioritizationFee,
idsSource: 'api',
idsSource: 'get-program-accounts',
postSendTxCallback: ({ txid }: { txid: string }) => {
notify({
title: 'Transaction sent',

View File

@ -2,9 +2,7 @@
export const BORROW_TOKEN = 'SOL'
export const STAKEABLE_TOKENS_DATA = [
{ name: 'MSOL', id: 521, active: true },
{ name: 'JitoSOL', id: 621, active: true },
{ name: 'bSOL', id: 721, active: true },
{ name: 'JLP', id: 1, active: true },
]
export const STAKEABLE_TOKENS = STAKEABLE_TOKENS_DATA.filter(
(d) => d.active,
@ -21,10 +19,10 @@ export const CLIENT_TX_TIMEOUT = 90000
export const SECONDS = 1000
export const INPUT_TOKEN_DEFAULT = 'SOL'
export const INPUT_TOKEN_DEFAULT = 'USDC'
export const MANGO_MINT = 'MangoCzJ36AjZyKwVj3VnYU4GTonjfVEnJmvvWaxLac'
export const USDC_MINT = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'
export const OUTPUT_TOKEN_DEFAULT = 'MSOL'
export const OUTPUT_TOKEN_DEFAULT = 'JLP'
export const JUPITER_V4_PROGRAM_ID =
'JUP4Fb2cqiRUcaTHdrPC8h2gNsA2ETXiPDD33WcGuJB'

View File

@ -46,12 +46,12 @@ export const withdrawAndClose = async (
) => {
console.log('withdraw and close')
const solBank = group?.banksMapByName.get('SOL')?.[0]
const borrowBank = group?.banksMapByName.get('USDC')?.[0]
const stakeBank = group?.banksMapByMint.get(stakeMintPk.toString())?.[0]
const instructions: TransactionInstruction[] = []
if (!solBank || !stakeBank || !mangoAccount) {
throw Error('Unable to find SOL bank or stake bank or mango account')
if (!borrowBank || !stakeBank || !mangoAccount) {
throw Error('Unable to find USDC bank or stake bank or mango account')
}
const stakeBalance = mangoAccount.getTokenBalanceUi(stakeBank)
const withdrawHealthRemainingAccounts: PublicKey[] =
@ -115,23 +115,23 @@ export const unstakeAndSwap = async (
console.log('unstake and swap')
const payer = (client.program.provider as AnchorProvider).wallet.publicKey
const solBank = group?.banksMapByName.get('SOL')?.[0]
const borrowBank = group?.banksMapByName.get('USDC')?.[0]
const stakeBank = group?.banksMapByMint.get(stakeMintPk.toString())?.[0]
const instructions: TransactionInstruction[] = []
if (!solBank || !stakeBank || !mangoAccount) {
throw Error('Unable to find SOL bank or stake bank or mango account')
if (!borrowBank || !stakeBank || !mangoAccount) {
throw Error('Unable to find borrow bank or stake bank or mango account')
}
const borrowedSol = mangoAccount.getTokenBalance(solBank)
const borrowed = mangoAccount.getTokenBalance(borrowBank)
let swapAlts: AddressLookupTableAccount[] = []
if (borrowedSol.toNumber() < 0) {
console.log('borrowedSol amount: ', borrowedSol.toNumber())
if (borrowed.toNumber() < 0) {
console.log('borrowedSol amount: ', borrowed.toNumber())
const { bestRoute: selectedRoute } = await fetchJupiterRoutes(
stakeMintPk.toString(),
solBank.mint.toString(),
Math.ceil(borrowedSol.abs().add(I80F48.fromNumber(100)).toNumber()),
borrowBank.mint.toString(),
Math.ceil(borrowed.abs().add(I80F48.fromNumber(100)).toNumber()),
500,
'ExactOut',
)
@ -146,7 +146,7 @@ export const unstakeAndSwap = async (
selectedRoute,
payer,
slippage,
solBank.mint,
borrowBank.mint,
stakeMintPk,
)
@ -160,7 +160,7 @@ export const unstakeAndSwap = async (
owner: payer,
inputMintPk: stakeBank.mint,
amountIn: toUiDecimals(selectedRoute.inAmount, stakeBank.mintDecimals),
outputMintPk: solBank.mint,
outputMintPk: borrowBank.mint,
userDefinedInstructions: jupiterIxs,
userDefinedAlts: jupiterAlts,
flashLoanType: FlashLoanType.swap,
@ -186,12 +186,12 @@ export const stakeAndCreate = async (
name?: string,
): Promise<MangoSignatureStatus> => {
const payer = (client.program.provider as AnchorProvider).wallet.publicKey
const solBank = group?.banksMapByName.get('SOL')?.[0]
const borrowBank = group?.banksMapByName.get('USDC')?.[0]
const stakeBank = group?.banksMapByMint.get(stakeMintPk.toString())?.[0]
const instructions: TransactionInstruction[] = []
if (!solBank || !stakeBank) {
throw Error('Unable to find SOL bank or Stake bank')
if (!borrowBank || !stakeBank) {
throw Error('Unable to find Borrow bank or Stake bank')
}
let mangoAccountPk = mangoAccount?.publicKey
@ -252,12 +252,12 @@ export const stakeAndCreate = async (
let swapAlts: AddressLookupTableAccount[] = []
const nativeBorrowAmount = toNative(
borrowAmount,
solBank.mintDecimals,
borrowBank.mintDecimals,
).toNumber()
if (nativeBorrowAmount) {
const { bestRoute: selectedRoute } = await fetchJupiterRoutes(
solBank.mint.toString(),
borrowBank.mint.toString(),
stakeMintPk.toString(),
nativeBorrowAmount,
)
@ -272,7 +272,7 @@ export const stakeAndCreate = async (
selectedRoute,
payer,
slippage,
solBank.mint,
borrowBank.mint,
stakeMintPk,
)
@ -281,7 +281,7 @@ export const stakeAndCreate = async (
group: group,
mangoAccountPk,
owner: payer,
inputMintPk: solBank.mint,
inputMintPk: borrowBank.mint,
amountIn: borrowAmount,
outputMintPk: stakeBank.mint,
userDefinedInstructions: jupiterIxs,