Skip to content

Commit

Permalink
Feature/mngo set market mode (solana-labs#766)
Browse files Browse the repository at this point in the history
* cleanup

* remove duplicates of instructions

* set market mode

* fix

* fix decode instruction

* fix program id param set market mode
  • Loading branch information
abrzezinski94 authored Jun 17, 2022
1 parent 16ff0c2 commit 3aa27ed
Show file tree
Hide file tree
Showing 19 changed files with 385 additions and 98 deletions.
1 change: 0 additions & 1 deletion Strategies/components/WithdrawModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ const WithdrawModal = ({
),
amount: yup.string().required('Amount is required'),
})
console.log(selectedMangoAccount.spotOpenOrders.map((x) => x.toBase58()))
const handlePropose = async (idx: number) => {
const isValid = await validateInstruction({ schema, form, setFormErrors })
if (!isValid) {
Expand Down
3 changes: 0 additions & 3 deletions SwitchboardVotePlugin/SwitchboardQueueVoterClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export async function grantPermissionTx(
switchboardProgram: PublicKey,
permission: PublicKey
): Promise<Transaction> {
console.log('IN GRANT FUNC')
const [addinState] = await PublicKey.findProgramAddress(
[Buffer.from('state')],
program.programId
Expand All @@ -70,8 +69,6 @@ export async function revokePermissionTx(
switchboardProgram: PublicKey,
permission: PublicKey
): Promise<Transaction> {
console.log('IN REVOKE FUNC')

const [addinState] = await PublicKey.findProgramAddress(
[Buffer.from('state')],
program.programId
Expand Down
2 changes: 0 additions & 2 deletions components/NotificationsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ const NotificationsCard = () => {
if (alertResult.targetGroup?.telegramTargets?.length > 0) {
const target = alertResult.targetGroup?.telegramTargets[0]
if (target && !target.isConfirmed) {
console.log(target.confirmationUrl)
if (target.confirmationUrl) {
window.open(target.confirmationUrl)
}
Expand All @@ -168,7 +167,6 @@ const NotificationsCard = () => {
if (alertResult.targetGroup?.telegramTargets?.length > 0) {
const target = alertResult.targetGroup?.telegramTargets[0]
if (target && !target.isConfirmed) {
console.log(target.confirmationUrl)
if (target.confirmationUrl) {
window.open(target.confirmationUrl)
}
Expand Down
4 changes: 0 additions & 4 deletions components/TokenBalance/SwitchboardPermissionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ const SwitchboardPermissionCard = () => {
const switchboardRefreshInstructions = useSwitchboardPluginStore(
(s) => s.state.instructions
)
console.log('sbis:')
console.log()

const [tokenOwnerRecordPk, setTokenOwneRecordPk] = useState('')
const { realm, symbol } = useRealm()
Expand Down Expand Up @@ -67,8 +65,6 @@ const SwitchboardPermissionCard = () => {
</div>
<div className="space-y-4">
{(() => {
console.log(switchboardVoterWeight)
console.log(`does it equal zero: ${switchboardVoterWeight.isZero()}`)
if (switchboardVoterWeight.isZero()) {
return <span>You do not have voting rights</span>
} else {
Expand Down
1 change: 0 additions & 1 deletion components/TokenBalance/TokenBalanceCardWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ const TokenBalanceCardWrapper = ({
(!ownTokenRecord ||
ownTokenRecord.account.governingTokenDepositAmount.isZero())
) {
console.log('IS SWITCHBOARD MODE')
return <SwitchboardPermissionCard></SwitchboardPermissionCard>
}
//Default
Expand Down
44 changes: 24 additions & 20 deletions components/instructions/instructionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,21 +218,23 @@ export function InstructionProgram({
<span className="font-bold text-fgd-1 text-sm">Program</span>
<div className="flex items-center pt-1 lg:pt-0">
<a
className="text-sm hover:brightness-[1.15] focus:outline-none"
className="text-sm hover:brightness-[1.15] focus:outline-none flex items-center"
href={getExplorerUrl(endpoint, programId)}
target="_blank"
rel="noopener noreferrer"
>
{programId.toBase58()}
{programLabel && (
<div className="mt-1 text-fgd-3 lg:text-right text-xs">
{programLabel}
</div>
)}
<div>
{programId.toBase58()}
{programLabel && (
<div className="mt-1 text-fgd-3 lg:text-right text-xs">
{programLabel}
</div>
)}
</div>
<ExternalLinkIcon
className={`flex-shrink-0 h-4 w-4 ml-2 text-primary-light`}
/>
</a>
<ExternalLinkIcon
className={`flex-shrink-0 h-4 w-4 ml-2 text-primary-light`}
/>
</div>
</div>
)
Expand Down Expand Up @@ -276,21 +278,23 @@ export function InstructionAccount({
</div>
<div className="flex items-center">
<a
className="text-sm hover:brightness-[1.15] focus:outline-none"
className="text-sm hover:brightness-[1.15] focus:outline-none flex items-center"
href={getExplorerUrl(endpoint, accountMeta.pubkey)}
target="_blank"
rel="noopener noreferrer"
>
{accountMeta.pubkey.toBase58()}
{accountLabel && (
<div className="mt-0.5 text-fgd-3 text-right text-xs">
{accountLabel}
</div>
)}
<div>
{accountMeta.pubkey.toBase58()}
{accountLabel && (
<div className="mt-0.5 text-fgd-3 text-right text-xs">
{accountLabel}
</div>
)}
</div>
<ExternalLinkIcon
className={`flex-shrink-0 h-4 w-4 ml-2 text-primary-light`}
/>
</a>
<ExternalLinkIcon
className={`flex-shrink-0 h-4 w-4 ml-2 text-primary-light`}
/>
</div>
</div>
)
Expand Down
42 changes: 42 additions & 0 deletions components/instructions/programs/mango.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ import { Connection, PublicKey } from '@solana/web3.js'
import { AccountMetaData } from '@solana/spl-governance'
import {
Config,
IDS,
MangoClient,
MangoInstructionLayout,
} from '@blockworks-foundation/mango-client'
import dayjs from 'dayjs'
import { tryGetTokenMint } from '@utils/tokens'
import { getMintDecimalAmountFromNatural } from '@tools/sdk/units'
import {
ASSET_TYPE,
MARKET_MODE,
} from 'pages/dao/[symbol]/proposal/components/instructions/Mango/MakeSetMarketMode'

function displayInstructionArgument(decodedArgs, argName) {
return (
Expand Down Expand Up @@ -397,6 +402,43 @@ export const MANGO_INSTRUCTIONS = {
return <>{displayAllArgs(args)}</>
},
},
66: {
name: 'Mango v3: Set Market Mode',
accounts: {
0: { name: 'Mango Group' },
},
getDataUI: async (
_connection: Connection,
data: Uint8Array,
_accounts: AccountMetaData[]
) => {
const args = MangoInstructionLayout.decode(Buffer.from(data), 0)
.SetMarketMode
const mangoGroup = IDS.groups.find(
(x) => x.publicKey === _accounts[0].pubkey.toBase58()
)!
return (
<>
<div>
Market:{' '}
{
mangoGroup[
args.marketType === 0 ? 'spotMarkets' : 'perpMarkets'
]!.find((x) => x.marketIndex === Number(args.marketIndex))!.name
}
</div>
<div>
Market Mode:{' '}
{MARKET_MODE.find((x) => x.value === args.marketMode)?.name}
</div>
<div>
Market Type:{' '}
{ASSET_TYPE.find((x) => x.value === args.marketType)?.name}
</div>
</>
)
},
},
},
}

Expand Down
26 changes: 3 additions & 23 deletions hooks/useGovernanceAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,29 +292,9 @@ export default function useGovernanceAssets() {
isVisible: canUseProgramUpgradeInstruction && symbol === 'MNGO',
},
{
id: Instructions.Mint,
name: 'Mint Tokens',
isVisible: canUseMintInstruction,
},
{
id: Instructions.CreateAssociatedTokenAccount,
name: 'Create Associated Token Account',
isVisible: canUseAnyInstruction,
},
{
id: Instructions.Base64,
name: 'Execute Custom Instruction',
isVisible: canUseAnyInstruction,
},
{
id: Instructions.VotingMintConfig,
name: 'Vote Escrowed Tokens: Configure Voting Mint',
isVisible: canUseAuthorityInstruction,
},
{
id: Instructions.CreateVsrRegistrar,
name: 'Vote Escrowed Tokens: Create Registrar',
isVisible: canUseAuthorityInstruction,
id: Instructions.MangoSetMarketMode,
name: 'Mango: Set Market Mode',
isVisible: canUseProgramUpgradeInstruction && symbol === 'MNGO',
},
{
id: Instructions.DepositIntoVolt,
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
]
},
"dependencies": {
"@switchboard-xyz/switchboard-v2": "^0.0.110",
"@blockworks-foundation/mango-client": "^3.5.0",
"@blockworks-foundation/mango-client": "^3.6.3",
"@blockworks-foundation/voter-stake-registry-client": "^0.2.3",
"@cardinal/namespaces-components": "^2.5.5",
"@castlefinance/vault-core": "^0.1.3",
Expand All @@ -33,8 +32,8 @@
"@dialectlabs/react-ui": "0.8.2",
"@emotion/react": "^11.9.0",
"@emotion/styled": "^11.8.1",
"@friktion-labs/friktion-sdk": "^1.1.118",
"@foresight-tmp/foresight-sdk": "^0.1.46",
"@friktion-labs/friktion-sdk": "^1.1.118",
"@headlessui/react": "^1.6.0",
"@heroicons/react": "^1.0.1",
"@marinade.finance/marinade-ts-sdk": "^2.0.9",
Expand Down Expand Up @@ -64,6 +63,7 @@
"@solana/wallet-adapter-torus": "^0.11.11",
"@solana/web3.js": "^1.37.1",
"@solendprotocol/solend-sdk": "^0.5.5",
"@switchboard-xyz/switchboard-v2": "^0.0.110",
"@tippyjs/react": "^4.2.6",
"axios": "^0.26.1",
"bignumber.js": "^9.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { useState, useEffect } from 'react'
import GovernedAccountSelect from '../GovernedAccountSelect'
import { precision } from '@utils/formatting'
import Switch from '@components/Switch'
import Select from '@components/inputs/Select'

export enum InstructionInputType {
GOVERNED_ACCOUNT,
INPUT,
TEXTAREA,
SWITCH,
SELECT,
}

export interface InstructionInput {
Expand Down Expand Up @@ -110,6 +112,26 @@ const InstructionInput = ({
governance={input.governance}
/>
)
case InstructionInputType.SELECT:
return (
<Select
label={input.label}
value={form[input.name]?.name}
placeholder="Please select..."
onChange={(value) => {
handleSetForm({ value, propertyName: input.name })
}}
error={formErrors[input.name]}
>
{input.options?.map((x, idx) => (
<Select.Option key={idx} value={x}>
<div className="flex flex-col">
<span>{x.name}</span>
</div>
</Select.Option>
))}
</Select>
)
case InstructionInputType.INPUT: {
const validateAmountOnBlur = () => {
const value = form[input.name]
Expand Down
Loading

0 comments on commit 3aa27ed

Please sign in to comment.