This commit is contained in:
Adrian Brzeziński 2023-05-28 22:44:26 +02:00
parent 0f32b5b89e
commit c46ac29a89
9 changed files with 196 additions and 112 deletions

View File

@ -25,6 +25,7 @@ import {
import { createProposal } from 'utils/governance/instructions/createProposal'
import { getBestMarket } from 'utils/governance/listingTools'
import { notify } from 'utils/notifications'
import ListTokenSuccess from '../ListToken/ListTokenSuccess'
type FormErrors = Partial<Record<keyof ListMarketForm, string>>
@ -58,12 +59,14 @@ const ListMarket = () => {
const availableTokens = group ? [...group.banksMapByName.keys()] : []
const client = mangoStore((s) => s.client)
const voter = GovernanceStore((s) => s.voter)
const vsrClient = GovernanceStore((s) => s.vsrClient)
const proposals = GovernanceStore((s) => s.proposals)
const [advForm, setAdvForm] = useState<ListMarketForm>({
...defaultFormValues,
})
const [proposalPk, setProposalPk] = useState<string | null>(null)
const [formErrors, setFormErrors] = useState<FormErrors>({})
const [baseToken, setBaseToken] = useState<null | string>(null)
const [quoteToken, setQuoteToken] = useState<null | string>(null)
@ -92,6 +95,7 @@ const ListMarket = () => {
const goToHomePage = async () => {
setCurrentView(VIEWS.BASE_TOKEN)
setMarketPk('')
setProposalPk('')
setAdvForm({
...defaultFormValues,
})
@ -99,8 +103,8 @@ const ListMarket = () => {
const handlePropose = useCallback(async () => {
setProposing(true)
const index = proposals ? Object.values(proposals).length : 0
const proposalTx = []
const registerMarketix = await client!.program.methods
.serum3RegisterMarket(advForm.marketIndex, advForm.marketName)
.accounts({
@ -113,6 +117,7 @@ const ListMarket = () => {
payer: MANGO_DAO_WALLET,
})
.instruction()
proposalTx.push(registerMarketix)
const walletSigner = wallet as never
@ -128,7 +133,8 @@ const ListMarket = () => {
proposalTx,
vsrClient!
)
console.log(proposalAddress)
setProposalPk(proposalAddress.toBase58())
setCurrentView(VIEWS.SUCCESS)
} catch (e) {
notify({
title: t('error-proposal-creation'),
@ -146,7 +152,7 @@ const ListMarket = () => {
proposals,
quoteBank,
t,
voter.tokenOwnerRecord,
voter,
vsrClient,
wallet,
])
@ -172,13 +178,6 @@ const ListMarket = () => {
setLoadingMarketProps(false)
}, [baseBank, quoteBank, connection])
useEffect(() => {
setAdvForm((prevForm) => ({
...prevForm,
openBookMarketExternalPk: marketPk,
}))
}, [marketPk])
useEffect(() => {
const index = proposals ? Object.values(proposals).length : 0
@ -187,12 +186,19 @@ const ListMarket = () => {
marketIndex: Number(index),
marketName: marketName,
proposalTitle: `List market ${marketName}`,
openBookMarketExternalPk: marketPk,
}))
}, [marketName, proposals])
}, [marketName, proposals, marketPk])
return (
<div className="h-full">
<h1 className="mb-4 flex items-center">{t('new-market-listing')}</h1>
{proposalPk && currentView === VIEWS.SUCCESS && (
<ListTokenSuccess
proposalPk={proposalPk}
token={advForm?.marketName}
></ListTokenSuccess>
)}
{currentView === VIEWS.BASE_TOKEN && (
<div className="mb-6">
<h2 className="mb-2 text-lg">{t('before-you-list-market')}</h2>
@ -223,9 +229,7 @@ const ListMarket = () => {
onChange={(token) => setBaseToken(token)}
className="w-full"
>
{availableTokens
.filter((x) => x !== quoteToken)
.map((token) => (
{availableTokens.map((token) => (
<Select.Option key={token} value={token}>
<div className="flex w-full items-center justify-between">
{token}
@ -241,9 +245,7 @@ const ListMarket = () => {
onChange={(token) => setQuoteToken(token)}
className="w-full"
>
{availableTokens
.filter((x) => x !== baseToken)
.map((token) => (
{availableTokens.map((token) => (
<Select.Option key={token} value={token}>
<div className="flex w-full items-center justify-between">
{token}

View File

@ -136,6 +136,11 @@ const CreateOpenbookMarketModal = ({
signature: sig,
})
}
onClose()
notify({
title: t('market-created-successful'),
type: 'success',
})
} catch (e) {
notify({
title: t('error-creating-market'),
@ -145,7 +150,6 @@ const CreateOpenbookMarketModal = ({
})
}
setCreating(false)
onClose()
}
useEffect(() => {
@ -179,7 +183,8 @@ const CreateOpenbookMarketModal = ({
return (
<Modal isOpen={isOpen} onClose={onClose}>
<p>Creating market will cost at least {solNeededToCreateMarket} sol</p>
<div className="space-y-4">
<p>Creating market will cost at least {solNeededToCreateMarket} SOL</p>
<div>
<Label text={t('open-book-market-id')} />
<Input
@ -254,6 +259,7 @@ const CreateOpenbookMarketModal = ({
</div>
)}
</div>
</div>
<div>
<Button
className="float-right mt-6 flex w-36 items-center justify-center"

View File

@ -77,5 +77,16 @@
"select-delegate": "Select delegate",
"new-market-listing": "New Market Listing",
"before-you-list-market": "Before you propose listing a market on Mango:",
"before-listing-market-2": "New markets are approved by DAO vote. This takes 3 days"
"before-listing-market-2": "New markets are approved by DAO vote. This takes 3 days",
"base-token": "Base token",
"quote-token": "Quote token",
"market-index": "Market index",
"creating-market-will-cost": "Creating market will cost at least",
"open-book-market-id": "Openbook market id",
"base-mint": "Base mint",
"quote-mint": "Quote mint",
"min-order": "Min order",
"price-tick": "Price tick",
"market-created-successful": "Market created successful",
"error-creating-market": "Error during market creation"
}

View File

@ -74,5 +74,19 @@
"no": "No",
"current-vote": "Current Vote:",
"use-own-wallet": "Use own wallet",
"select-delegate": "Select delegate"
"select-delegate": "Select delegate",
"new-market-listing": "New Market Listing",
"before-you-list-market": "Before you propose listing a market on Mango:",
"before-listing-market-2": "New markets are approved by DAO vote. This takes 3 days",
"base-token": "Base token",
"quote-token": "Quote token",
"market-index": "Market index",
"creating-market-will-cost": "Creating market will cost at least",
"open-book-market-id": "Openbook market id",
"base-mint": "Base mint",
"quote-mint": "Quote mint",
"min-order": "Min order",
"price-tick": "Price tick",
"market-created-successful": "Market created successful",
"error-creating-market": "Error during market creation"
}

View File

@ -74,5 +74,19 @@
"no": "No",
"current-vote": "Current Vote:",
"use-own-wallet": "Use own wallet",
"select-delegate": "Select delegate"
"select-delegate": "Select delegate",
"new-market-listing": "New Market Listing",
"before-you-list-market": "Before you propose listing a market on Mango:",
"before-listing-market-2": "New markets are approved by DAO vote. This takes 3 days",
"base-token": "Base token",
"quote-token": "Quote token",
"market-index": "Market index",
"creating-market-will-cost": "Creating market will cost at least",
"open-book-market-id": "Openbook market id",
"base-mint": "Base mint",
"quote-mint": "Quote mint",
"min-order": "Min order",
"price-tick": "Price tick",
"market-created-successful": "Market created successful",
"error-creating-market": "Error during market creation"
}

View File

@ -74,5 +74,19 @@
"no": "No",
"current-vote": "Current Vote:",
"use-own-wallet": "Use own wallet",
"select-delegate": "Select delegate"
"select-delegate": "Select delegate",
"new-market-listing": "New Market Listing",
"before-you-list-market": "Before you propose listing a market on Mango:",
"before-listing-market-2": "New markets are approved by DAO vote. This takes 3 days",
"base-token": "Base token",
"quote-token": "Quote token",
"market-index": "Market index",
"creating-market-will-cost": "Creating market will cost at least",
"open-book-market-id": "Openbook market id",
"base-mint": "Base mint",
"quote-mint": "Quote mint",
"min-order": "Min order",
"price-tick": "Price tick",
"market-created-successful": "Market created successful",
"error-creating-market": "Error during market creation"
}

View File

@ -74,5 +74,19 @@
"no": "No",
"current-vote": "Current Vote:",
"use-own-wallet": "Use own wallet",
"select-delegate": "Select delegate"
"select-delegate": "Select delegate",
"new-market-listing": "New Market Listing",
"before-you-list-market": "Before you propose listing a market on Mango:",
"before-listing-market-2": "New markets are approved by DAO vote. This takes 3 days",
"base-token": "Base token",
"quote-token": "Quote token",
"market-index": "Market index",
"creating-market-will-cost": "Creating market will cost at least",
"open-book-market-id": "Openbook market id",
"base-mint": "Base mint",
"quote-mint": "Quote mint",
"min-order": "Min order",
"price-tick": "Price tick",
"market-created-successful": "Market created successful",
"error-creating-market": "Error during market creation"
}

View File

@ -43,7 +43,10 @@ export async function castVote(
)
const { updateVoterWeightRecordIx, voterWeightPk } =
await updateVoterWeightRecord(vsrClient, walletPubkey)
await updateVoterWeightRecord(
vsrClient,
tokenOwnerRecord.account.governingTokenOwner
)
instructions.push(updateVoterWeightRecordIx)
// It is not clear that defining these extraneous fields, `deny` and `veto`, is actually necessary.
@ -97,7 +100,10 @@ export async function castVote(
if (message) {
const { updateVoterWeightRecordIx, voterWeightPk } =
await updateVoterWeightRecord(vsrClient, walletPubkey)
await updateVoterWeightRecord(
vsrClient,
tokenOwnerRecord.account.governingTokenOwner
)
instructions.push(updateVoterWeightRecordIx)
await withPostChatMessage(

View File

@ -53,7 +53,10 @@ export const createProposal = async (
const useDenyOption = true
const { updateVoterWeightRecordIx, voterWeightPk } =
await updateVoterWeightRecord(client, walletPk)
await updateVoterWeightRecord(
client,
tokenOwnerRecord.account.governingTokenOwner
)
instructions.push(updateVoterWeightRecordIx)
const proposalAddress = await withCreateProposal(