market props json
This commit is contained in:
parent
67ddce6163
commit
7303b63a7b
|
@ -1,3 +1,4 @@
|
|||
import { OPENBOOK_PROGRAM_ID } from '@blockworks-foundation/mango-v4'
|
||||
import Input from '@components/forms/Input'
|
||||
import Label from '@components/forms/Label'
|
||||
import Select from '@components/forms/Select'
|
||||
|
@ -15,6 +16,7 @@ import useMangoGroup from 'hooks/useMangoGroup'
|
|||
import { useTranslation } from 'next-i18next'
|
||||
import { ChangeEvent, useCallback, useState } from 'react'
|
||||
import { getBestMarket } from 'utils/governance/listingTools'
|
||||
import { getTokenExcel } from 'utils/governance/testScript'
|
||||
|
||||
type FormErrors = Partial<Record<keyof ListMarketForm, string>>
|
||||
|
||||
|
@ -105,6 +107,13 @@ const ListMarket = () => {
|
|||
return (
|
||||
<div className="h-full">
|
||||
<h1 className="mb-4 flex items-center">{t('new-market-listing')}</h1>
|
||||
<Button
|
||||
onClick={() =>
|
||||
getTokenExcel(group, connection, OPENBOOK_PROGRAM_ID[CLUSTER])
|
||||
}
|
||||
>
|
||||
Excel
|
||||
</Button>
|
||||
{currentView === VIEWS.BASE_TOKEN && (
|
||||
<div className="mb-6">
|
||||
<h2 className="mb-2 text-lg">{t('before-you-list-market')}</h2>
|
||||
|
|
|
@ -76,6 +76,7 @@ const CreateOpenbookMarketModal = ({
|
|||
baseLotSize: 0,
|
||||
}
|
||||
}, [baseBank, quoteBank])
|
||||
console.log(tradingParams)
|
||||
|
||||
const handleSetAdvForm = (propertyName: string, value: string | number) => {
|
||||
setFormErrors({})
|
||||
|
|
|
@ -214,11 +214,13 @@ export function calculateTradingParameters(
|
|||
let priceIncrement = 0
|
||||
let baseLotExponent = 20
|
||||
let quoteLotExponent = 20
|
||||
let minOrderValue = 0
|
||||
let priceIncrementRelative = 0
|
||||
|
||||
// Calculate minimum order size
|
||||
do {
|
||||
minOrderSize = Math.pow(10, baseLotExponent - baseDecimals)
|
||||
const minOrderValue = basePrice * minOrderSize
|
||||
minOrderValue = basePrice * minOrderSize
|
||||
|
||||
if (minOrderValue < MAX_MIN_ORDER_VALUE) {
|
||||
break
|
||||
|
@ -233,7 +235,7 @@ export function calculateTradingParameters(
|
|||
10,
|
||||
quoteLotExponent + baseDecimals - baseLotExponent - quoteDecimals
|
||||
)
|
||||
const priceIncrementRelative = (priceIncrement * basePrice) / quotePrice
|
||||
priceIncrementRelative = (priceIncrement * basePrice) / quotePrice
|
||||
if (priceIncrementRelative < MIN_PRICE_INCREMENT_RELATIVE) {
|
||||
break
|
||||
}
|
||||
|
@ -241,8 +243,12 @@ export function calculateTradingParameters(
|
|||
quoteLotExponent--
|
||||
} while (quoteLotExponent > 0)
|
||||
return {
|
||||
minOrderValue: minOrderValue,
|
||||
baseLotExponent: baseLotExponent,
|
||||
quoteLotExponent: quoteLotExponent,
|
||||
minOrder: minOrderSize,
|
||||
priceTick: priceIncrement,
|
||||
priceIncrementRelative: priceIncrementRelative,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
import { Group } from '@blockworks-foundation/mango-v4'
|
||||
import { calculateTradingParameters } from './listingTools'
|
||||
import { Market } from '@project-serum/serum'
|
||||
import { Connection, PublicKey } from '@solana/web3.js'
|
||||
|
||||
//this will be moved to other repository before merge
|
||||
export async function getTokenExcel(
|
||||
group: Group | undefined,
|
||||
connection: Connection,
|
||||
dexProgramPk: PublicKey
|
||||
) {
|
||||
if (!group) {
|
||||
console.log('error')
|
||||
return
|
||||
}
|
||||
const rows = []
|
||||
const tokens = [...group.banksMapByName.values()].flatMap((x) => x[0])
|
||||
for (const baseToken of tokens) {
|
||||
for (const quoteToken of tokens) {
|
||||
const baseMint = baseToken.mint
|
||||
const quoteMint = quoteToken.mint
|
||||
|
||||
if (!baseMint.equals(quoteMint)) {
|
||||
const calcedParams = calculateTradingParameters(
|
||||
baseToken.uiPrice,
|
||||
quoteToken.uiPrice,
|
||||
baseToken.mintDecimals,
|
||||
quoteToken.mintDecimals
|
||||
)
|
||||
const mangoMarkets = [...group.serum3ExternalMarketsMap.values()]
|
||||
const mangoParams = mangoMarkets.find(
|
||||
(x) =>
|
||||
x.quoteMintAddress.equals(quoteMint) &&
|
||||
x.baseMintAddress.equals(baseMint)
|
||||
)
|
||||
|
||||
const markets = await Market.findAccountsByMints(
|
||||
connection,
|
||||
baseMint,
|
||||
quoteMint,
|
||||
dexProgramPk
|
||||
)
|
||||
const decodedMarkets = await markets
|
||||
.map(
|
||||
(x) =>
|
||||
new Market(
|
||||
Market.getLayout(dexProgramPk).decode(x.accountInfo.data),
|
||||
baseToken.mintDecimals,
|
||||
quoteToken.mintDecimals,
|
||||
{},
|
||||
dexProgramPk
|
||||
)
|
||||
)
|
||||
.sort(
|
||||
(a, b) =>
|
||||
b.decoded.baseDepositsTotal.toNumber() -
|
||||
a.decoded.baseDepositsTotal.toNumber()
|
||||
)
|
||||
const mostUsedMarket = decodedMarkets?.length ? decodedMarkets[0] : null
|
||||
|
||||
try {
|
||||
const obj = {
|
||||
pair: `${baseToken.name}/${quoteToken.name}`,
|
||||
baseToken: baseToken.name,
|
||||
basePrice: baseToken.uiPrice,
|
||||
baseDecimals: baseToken.mintDecimals,
|
||||
quoteToken: quoteToken.name,
|
||||
quotePrice: quoteToken.uiPrice,
|
||||
quoteDecimals: quoteToken.mintDecimals,
|
||||
//params from tool
|
||||
baseLotExponent: calcedParams.baseLotExponent,
|
||||
minOrderSize: calcedParams.minOrder,
|
||||
minOrderValue: calcedParams.minOrderValue,
|
||||
quoteLotExponent: calcedParams.quoteLotExponent,
|
||||
priceIncrement: calcedParams.priceTick,
|
||||
priceIncrementRelative: calcedParams.priceIncrementRelative,
|
||||
//serum market
|
||||
market_baseLotExponent: mangoParams
|
||||
? Math.log10(
|
||||
mangoParams?.baseSizeLotsToNumber(
|
||||
mangoParams.decoded.baseLotSize
|
||||
)
|
||||
)
|
||||
: mostUsedMarket
|
||||
? Math.log10(
|
||||
mostUsedMarket.baseSizeLotsToNumber(
|
||||
mostUsedMarket.decoded.baseLotSize
|
||||
)
|
||||
)
|
||||
: '',
|
||||
market_minOrderSize: mangoParams
|
||||
? mangoParams.minOrderSize
|
||||
: mostUsedMarket
|
||||
? mostUsedMarket.minOrderSize
|
||||
: '',
|
||||
market_minOrderValue: mangoParams
|
||||
? mangoParams.minOrderSize * baseToken.uiPrice
|
||||
: mostUsedMarket
|
||||
? mostUsedMarket.minOrderSize * baseToken.uiPrice
|
||||
: '',
|
||||
market_quoteLotExponent: mangoParams
|
||||
? Math.log10(
|
||||
mangoParams?.quoteSizeLotsToNumber(
|
||||
mangoParams.decoded.quoteLotSize
|
||||
)
|
||||
)
|
||||
: mostUsedMarket
|
||||
? Math.log10(
|
||||
mostUsedMarket.quoteSizeLotsToNumber(
|
||||
mostUsedMarket.decoded.quoteLotSize
|
||||
)
|
||||
)
|
||||
: '',
|
||||
market_priceIncrement: mangoParams
|
||||
? mangoParams.tickSize
|
||||
: mostUsedMarket
|
||||
? mostUsedMarket.tickSize
|
||||
: '',
|
||||
market_priceIncrementRelative: mangoParams
|
||||
? mangoParams.tickSize * baseToken.uiPrice
|
||||
: mostUsedMarket
|
||||
? mostUsedMarket.tickSize * baseToken.uiPrice
|
||||
: '',
|
||||
}
|
||||
rows.push(obj)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(rows)
|
||||
}
|
Loading…
Reference in New Issue