From cc0ef814c9b9f8bc093144a852c16c3b6c447de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Brzezin=CC=81ski?= Date: Wed, 8 Dec 2021 22:23:28 +0100 Subject: [PATCH 1/7] mango max accounts instruction ui --- hooks/useGovernanceAssets.ts | 12 +- .../Mango/MakeChangeMaxAccounts.tsx | 128 ++++++++++++++++++ .../instructions/ProgramUpgrade.tsx | 1 - pages/dao/[symbol]/proposal/new.tsx | 8 ++ utils/uiTypes/proposalCreationTypes.ts | 7 + 5 files changed, 152 insertions(+), 4 deletions(-) create mode 100644 pages/dao/[symbol]/proposal/components/instructions/Mango/MakeChangeMaxAccounts.tsx diff --git a/hooks/useGovernanceAssets.ts b/hooks/useGovernanceAssets.ts index 1b4821905c..fc2bfbfc99 100644 --- a/hooks/useGovernanceAssets.ts +++ b/hooks/useGovernanceAssets.ts @@ -1,3 +1,4 @@ +import { Cluster } from '@blockworks-foundation/mango-client/lib/src/config' import { GovernanceAccountType } from '@models/accounts' import { MintInfo } from '@solana/spl-token' import { @@ -9,11 +10,11 @@ import { import { Instructions } from '@utils/uiTypes/proposalCreationTypes' import useWalletStore from 'stores/useWalletStore' import useRealm from './useRealm' + export default function useGovernanceAssets() { const { governances, tokenMints, realmTokenAccounts } = useRealm() const connection = useWalletStore((s) => s.connection.current) - const { ownVoterWeight, realm } = useRealm() - + const { ownVoterWeight, realm, symbol } = useRealm() const governancesArray = Object.keys(governances).map( (key) => governances[key] ) @@ -49,7 +50,7 @@ export default function useGovernanceAssets() { governancesArray.some((g) => ownVoterWeight.canCreateProposal(g.info.config) ) - + console.log(symbol, ' @@@@@@@@@') const availableInstructions = [ { id: Instructions.Transfer, @@ -71,6 +72,11 @@ export default function useGovernanceAssets() { name: 'Execute Custom Instruction', isVisible: canUseAnyInstruction, }, + { + id: Instructions.MangoMakeChangeMaxAccounts, + name: 'Mango - change max accounts', + isVisible: canUseProgramUpgradeInstruction && symbol === 'MNGO', + }, { id: Instructions.None, name: 'None', diff --git a/pages/dao/[symbol]/proposal/components/instructions/Mango/MakeChangeMaxAccounts.tsx b/pages/dao/[symbol]/proposal/components/instructions/Mango/MakeChangeMaxAccounts.tsx new file mode 100644 index 0000000000..026b98309e --- /dev/null +++ b/pages/dao/[symbol]/proposal/components/instructions/Mango/MakeChangeMaxAccounts.tsx @@ -0,0 +1,128 @@ +/* eslint-disable @typescript-eslint/no-non-null-assertion */ +import React, { useContext, useEffect, useState } from 'react' +import useRealm from '@hooks/useRealm' +import { PublicKey } from '@solana/web3.js' +import * as yup from 'yup' +import { isFormValid } from '@utils/formValidation' +import { + UiInstruction, + MangoMakeChangeMaxAccountsForm, +} from '@utils/uiTypes/proposalCreationTypes' +import { NewProposalContext } from '../../../new' +import useGovernanceAssets from '@hooks/useGovernanceAssets' +import { Governance, GovernanceAccountType } from '@models/accounts' +import { ParsedAccount } from '@models/core/accounts' +import useWalletStore from 'stores/useWalletStore' +//import { serializeInstructionToBase64 } from '@models/serialisation' +import Input from '@components/inputs/Input' +import GovernedAccountSelect from '../../GovernedAccountSelect' +import { GovernedMultiTypeAccount } from '@utils/tokens' + +const MakeChangeMaxAccounts = ({ + index, + governance, +}: { + index: number + governance: ParsedAccount | null +}) => { + const wallet = useWalletStore((s) => s.current) + const { realmInfo } = useRealm() + const { getGovernancesByAccountType } = useGovernanceAssets() + const governedProgramAccounts = getGovernancesByAccountType( + GovernanceAccountType.ProgramGovernance + ).map((x) => { + return { + governance: x, + } + }) + const shouldBeGoverned = index !== 0 && governance + const programId: PublicKey | undefined = realmInfo?.programId + const [form, setForm] = useState({ + governedAccount: undefined, + programId: programId?.toString(), + maxMangoAccounts: 1, + }) + const [formErrors, setFormErrors] = useState({}) + const { handleSetInstructions } = useContext(NewProposalContext) + const handleSetForm = ({ propertyName, value }) => { + setFormErrors({}) + setForm({ ...form, [propertyName]: value }) + } + const validateInstruction = async (): Promise => { + const { isValid, validationErrors } = await isFormValid(schema, form) + setFormErrors(validationErrors) + return isValid + } + async function getInstruction(): Promise { + const isValid = await validateInstruction() + let serializedInstruction = '' + if ( + isValid && + programId && + form.governedAccount?.governance?.info && + wallet?.publicKey + ) { + //const makeChangeMaxMangoAccountsInstructionIx = '' + //Mango instruction call and serialize + // serializedInstruction = serializeInstructionToBase64(makeChangeMaxMangoAccountsInstructionIx) + serializedInstruction = '' + } + const obj: UiInstruction = { + serializedInstruction: serializedInstruction, + isValid, + governedAccount: form.governedAccount?.governance, + } + return obj + } + useEffect(() => { + handleSetForm({ + propertyName: 'programId', + value: programId?.toString(), + }) + }, [realmInfo?.programId]) + + useEffect(() => { + handleSetInstructions( + { governedAccount: form.governedAccount?.governance, getInstruction }, + index + ) + }, [form]) + const schema = yup.object().shape({ + bufferAddress: yup.number(), + governedAccount: yup + .object() + .nullable() + .required('Program governed account is required'), + }) + + return ( + <> + { + handleSetForm({ value, propertyName: 'governedAccount' }) + }} + value={form.governedAccount} + error={formErrors['governedAccount']} + shouldBeGoverned={shouldBeGoverned} + governance={governance} + > + + handleSetForm({ + value: evt.target.value, + propertyName: 'maxMangoAccounts', + }) + } + error={formErrors['maxMangoAccounts']} + /> + + ) +} + +export default MakeChangeMaxAccounts diff --git a/pages/dao/[symbol]/proposal/components/instructions/ProgramUpgrade.tsx b/pages/dao/[symbol]/proposal/components/instructions/ProgramUpgrade.tsx index 96d78e11c6..e83e357053 100644 --- a/pages/dao/[symbol]/proposal/components/instructions/ProgramUpgrade.tsx +++ b/pages/dao/[symbol]/proposal/components/instructions/ProgramUpgrade.tsx @@ -20,7 +20,6 @@ import { debounce } from '@utils/debounce' import { validateBuffer } from '@utils/validations' import GovernedAccountSelect from '../GovernedAccountSelect' import { GovernedMultiTypeAccount } from '@utils/tokens' - const ProgramUpgrade = ({ index, governance, diff --git a/pages/dao/[symbol]/proposal/new.tsx b/pages/dao/[symbol]/proposal/new.tsx index 273573f6a8..dea2809c20 100644 --- a/pages/dao/[symbol]/proposal/new.tsx +++ b/pages/dao/[symbol]/proposal/new.tsx @@ -36,6 +36,7 @@ import Empty from './components/instructions/Empty' import Mint from './components/instructions/Mint' import CustomBase64 from './components/instructions/CustomBase64' import { getTimestampFromDays } from '@tools/sdk/units' +import MakeChangeMaxAccounts from './components/instructions/Mango/MakeChangeMaxAccounts' const schema = yup.object().shape({ title: yup.string().required('Title is required'), }) @@ -264,6 +265,13 @@ const New = () => { return case Instructions.None: return + case Instructions.MangoMakeChangeMaxAccounts: + return ( + + ) default: null } diff --git a/utils/uiTypes/proposalCreationTypes.ts b/utils/uiTypes/proposalCreationTypes.ts index 6e3790b103..8f7b01f9e7 100644 --- a/utils/uiTypes/proposalCreationTypes.ts +++ b/utils/uiTypes/proposalCreationTypes.ts @@ -42,6 +42,12 @@ export interface ProgramUpgradeForm { bufferAddress: string } +export interface MangoMakeChangeMaxAccountsForm { + governedAccount: GovernedProgramAccount | undefined + programId: string | undefined + maxMangoAccounts: number +} + export interface Base64InstructionForm { governedAccount: GovernedMultiTypeAccount | undefined base64: string @@ -58,6 +64,7 @@ export enum Instructions { Mint, Base64, None, + MangoMakeChangeMaxAccounts, } export type createParams = [ From 6803677e43b2f3898f64429aedce6a0f0224248a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Brzezin=CC=81ski?= Date: Wed, 8 Dec 2021 22:26:12 +0100 Subject: [PATCH 2/7] remove unused import --- hooks/useGovernanceAssets.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/hooks/useGovernanceAssets.ts b/hooks/useGovernanceAssets.ts index fc2bfbfc99..cb494370c2 100644 --- a/hooks/useGovernanceAssets.ts +++ b/hooks/useGovernanceAssets.ts @@ -1,4 +1,3 @@ -import { Cluster } from '@blockworks-foundation/mango-client/lib/src/config' import { GovernanceAccountType } from '@models/accounts' import { MintInfo } from '@solana/spl-token' import { From f9c416dd6fe2ab899a0503bbd5265e377b5e3eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Brzezin=CC=81ski?= Date: Wed, 8 Dec 2021 22:30:07 +0100 Subject: [PATCH 3/7] example comment --- .../instructions/Mango/MakeChangeMaxAccounts.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pages/dao/[symbol]/proposal/components/instructions/Mango/MakeChangeMaxAccounts.tsx b/pages/dao/[symbol]/proposal/components/instructions/Mango/MakeChangeMaxAccounts.tsx index 026b98309e..01f535f9ab 100644 --- a/pages/dao/[symbol]/proposal/components/instructions/Mango/MakeChangeMaxAccounts.tsx +++ b/pages/dao/[symbol]/proposal/components/instructions/Mango/MakeChangeMaxAccounts.tsx @@ -62,9 +62,16 @@ const MakeChangeMaxAccounts = ({ form.governedAccount?.governance?.info && wallet?.publicKey ) { - //const makeChangeMaxMangoAccountsInstructionIx = '' //Mango instruction call and serialize - // serializedInstruction = serializeInstructionToBase64(makeChangeMaxMangoAccountsInstructionIx) + //example + + // const upgradeIx = await createUpgradeInstruction( + // form.governedAccount.governance.info.governedAccount, + // new PublicKey(form.bufferAddress), + // form.governedAccount.governance.pubkey, + // wallet!.publicKey + // ) + // serializedInstruction = serializeInstructionToBase64(upgradeIx) serializedInstruction = '' } const obj: UiInstruction = { From cc8c10495f9b64d10b2a647b31e0d8c0dfc4b80a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Brzezin=CC=81ski?= Date: Wed, 8 Dec 2021 22:31:33 +0100 Subject: [PATCH 4/7] more comments --- .../components/instructions/Mango/MakeChangeMaxAccounts.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pages/dao/[symbol]/proposal/components/instructions/Mango/MakeChangeMaxAccounts.tsx b/pages/dao/[symbol]/proposal/components/instructions/Mango/MakeChangeMaxAccounts.tsx index 01f535f9ab..cd5447ed23 100644 --- a/pages/dao/[symbol]/proposal/components/instructions/Mango/MakeChangeMaxAccounts.tsx +++ b/pages/dao/[symbol]/proposal/components/instructions/Mango/MakeChangeMaxAccounts.tsx @@ -104,6 +104,8 @@ const MakeChangeMaxAccounts = ({ return ( <> + {/* if you need more fields add theme to interface MangoMakeChangeMaxAccountsForm + then you can add inputs in here */} Date: Wed, 8 Dec 2021 22:34:56 +0100 Subject: [PATCH 5/7] remove console log --- hooks/useGovernanceAssets.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/useGovernanceAssets.ts b/hooks/useGovernanceAssets.ts index cb494370c2..19c506b338 100644 --- a/hooks/useGovernanceAssets.ts +++ b/hooks/useGovernanceAssets.ts @@ -49,7 +49,7 @@ export default function useGovernanceAssets() { governancesArray.some((g) => ownVoterWeight.canCreateProposal(g.info.config) ) - console.log(symbol, ' @@@@@@@@@') + const availableInstructions = [ { id: Instructions.Transfer, From 1f75626e1ab3c53ac2d1033c41acdb9208f04188 Mon Sep 17 00:00:00 2001 From: Riordan Panayides Date: Mon, 20 Dec 2021 17:34:08 +0000 Subject: [PATCH 6/7] Update mango-client --- yarn.lock | 129 ++++++++++++++++++++++++++---------------------------- 1 file changed, 61 insertions(+), 68 deletions(-) diff --git a/yarn.lock b/yarn.lock index ec6bd8a4b9..66a40ab4be 100644 --- a/yarn.lock +++ b/yarn.lock @@ -291,9 +291,9 @@ regenerator-runtime "^0.13.4" "@babel/runtime@^7.10.5", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.5": - version "7.16.0" - resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.16.0.tgz#e27b977f2e2088ba24748bf99b5e1dece64e4f0b" - integrity sha512-Nht8L0O8YCktmsDV6FqFue7vQLRx3Hb0B37lS5y0jDRqRxlBG4wIJHnf9/bgSE2UyipKFA01YtS+npRdTWBUyw== + version "7.16.5" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.16.5.tgz#7f3e34bf8bdbbadf03fbb7b1ea0d929569c9487a" + integrity sha512-TXWihFIS3Pyv5hzR7j6ihmeLkZfrXGxAr5UfSl8CHf+6q/wpiYDkUau0czckpYG8QmnCIuPpdLtuA9VmuGGyMA== dependencies: regenerator-runtime "^0.13.4" @@ -338,22 +338,19 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" "@blockworks-foundation/mango-client@^3.2.2": - version "3.2.2" - resolved "https://registry.yarnpkg.com/@blockworks-foundation/mango-client/-/mango-client-3.2.2.tgz#f4681c02e784bea8b32dea0df922c50354b4a2c4" - integrity sha512-YQyJD7py1AbwWX/Fb8O980i11XuX098NGlo97Hp3oaZyrqkq3PYvJ3Ei3HR35+RhoSxiHOUda3AnOT/URXIz7Q== + version "3.2.16" + resolved "https://registry.yarnpkg.com/@blockworks-foundation/mango-client/-/mango-client-3.2.16.tgz#8379193841589db74642368aa04938ed06f02bc3" + integrity sha512-ZI3Tt/k77azt4iBrPiWsm9rS6EPEbGX+IsWKzCTCXLIfwOxpF09FarL+1YL/hBvoRkd8X/jAyQ1/KWpkb3zvUg== dependencies: "@project-serum/anchor" "^0.16.2" "@project-serum/serum" "0.13.55" "@project-serum/sol-wallet-adapter" "^0.2.0" "@solana/spl-token" "^0.1.6" "@solana/web3.js" "1.21.0" - axios "^0.21.1" big.js "^6.1.1" - bigint-buffer "^1.1.5" bn.js "^5.2.0" buffer-layout "^1.2.1" dotenv "^10.0.0" - dotenv-expand "^5.1.0" yargs "^17.0.1" "@cnakazawa/watch@^1.0.3": @@ -1012,10 +1009,10 @@ superstruct "^0.14.2" tweetnacl "^1.0.0" -"@solana/web3.js@^1.17.0", "@solana/web3.js@^1.21.0", "@solana/web3.js@^1.30.2": - version "1.30.2" - resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.30.2.tgz#e85da75e0825dc64f53eb64a1ff0115b27bec135" - integrity sha512-hznCj+rkfvM5taRP3Z+l5lumB7IQnDrB4l55Wpsg4kDU9Zds8pE5YOH5Z9bbF/pUzZJKQjyBjnY/6kScBm3Ugg== +"@solana/web3.js@^1.17.0", "@solana/web3.js@^1.21.0": + version "1.31.0" + resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.31.0.tgz#7a313d4c1a90b77f27ddbfe845a10d6883e06452" + integrity sha512-7nHHx1JNFnrt15e9y8m38I/EJCbaB+bFC3KZVM1+QhybCikFxGMtGA5r7PDC3GEL1R2RZA8yKoLkDKo3vzzqnw== dependencies: "@babel/runtime" "^7.12.5" "@ethersproject/sha2" "^5.5.0" @@ -1050,6 +1047,26 @@ superstruct "^0.14.2" tweetnacl "^1.0.0" +"@solana/web3.js@^1.30.2": + version "1.30.2" + resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.30.2.tgz#e85da75e0825dc64f53eb64a1ff0115b27bec135" + integrity sha512-hznCj+rkfvM5taRP3Z+l5lumB7IQnDrB4l55Wpsg4kDU9Zds8pE5YOH5Z9bbF/pUzZJKQjyBjnY/6kScBm3Ugg== + dependencies: + "@babel/runtime" "^7.12.5" + "@ethersproject/sha2" "^5.5.0" + "@solana/buffer-layout" "^3.0.0" + bn.js "^5.0.0" + borsh "^0.4.0" + bs58 "^4.0.1" + buffer "6.0.1" + cross-fetch "^3.1.4" + jayson "^3.4.4" + js-sha3 "^0.8.0" + rpc-websockets "^7.4.2" + secp256k1 "^4.0.2" + superstruct "^0.14.2" + tweetnacl "^1.0.0" + "@testing-library/dom@^7.28.1": version "7.30.4" resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-7.30.4.tgz#c6a4a91557e92035fd565246bbbfb8107aa4634d" @@ -1152,9 +1169,9 @@ "@types/ms" "*" "@types/express-serve-static-core@^4.17.9": - version "4.17.24" - resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.24.tgz#ea41f93bf7e0d59cd5a76665068ed6aab6815c07" - integrity sha512-3UJuW+Qxhzwjq3xhwXm2onQcFHn76frIYVbTu+kn24LFxI+dEhdfISDFovPB8VpEgW8oQCTpRuCe+0zJxB7NEA== + version "4.17.26" + resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.26.tgz#5d9a8eeecb9d5f9d7fc1d85f541512a84638ae88" + integrity sha512-zeu3tpouA043RHxW0gzRxwCHchMgftE8GArRsvYT0ByDMbn19olQHx5jLue0LxWY6iYtXb7rXmuVtSkhy9YZvQ== dependencies: "@types/node" "*" "@types/qs" "*" @@ -1202,9 +1219,9 @@ integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ== "@types/lodash@^4.14.159": - version "4.14.176" - resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.176.tgz#641150fc1cda36fbfa329de603bbb175d7ee20c0" - integrity sha512-xZmuPTa3rlZoIbtDUyJKZQimJV3bxCmzMIO2c9Pz9afyDro6kr7R79GwcB6mRhuoPmV2p1Vb66WOJH7F886WKQ== + version "4.14.178" + resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.178.tgz#341f6d2247db528d4a13ddbb374bcdc80406f4f8" + integrity sha512-0d5Wd09ItQWH1qFbEyQ7oTQ3GZrMfth5JkbN3EvTKLXcHLRDSXeLnlvlOn0wvxVIwK5o2M8JzP/OWz7T3NRsbw== "@types/lodash@^4.14.175": version "4.14.175" @@ -1229,14 +1246,14 @@ integrity sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA== "@types/node@*": - version "16.11.10" - resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.10.tgz#2e3ad0a680d96367103d3e670d41c2fed3da61ae" - integrity sha512-3aRnHa1KlOEEhJ6+CvyHKK5vE9BcLGjtUpwvqYLRvYNQKMfabu3BwfJaA/SLW8dxe28LsNDjtHwePTuzn3gmOA== + version "17.0.0" + resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.0.tgz#62797cee3b8b497f6547503b2312254d4fe3c2bb" + integrity sha512-eMhwJXc931Ihh4tkU+Y7GiLzT/y/DBNpNtr4yU9O2w3SYBsr9NaOPhQlLKRmoWtI54uNwuo0IOUFQjVOTZYRvw== "@types/node@^12.12.54": - version "12.20.36" - resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.36.tgz#5bd54d2383e714fc4d2c258107ee70c5bad86d0c" - integrity sha512-+5haRZ9uzI7rYqzDznXgkuacqb6LJhAti8mzZKWxIXn/WEtvB+GHVJ7AuMwcN1HMvXOSJcrvA6PPoYHYOYYebA== + version "12.20.37" + resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.37.tgz#abb38afa9d6e8a2f627a8cb52290b3c80fbe61ed" + integrity sha512-i1KGxqcvJaLQali+WuypQnXwcplhtNtjs66eNsZpp2P2FL/trJJxx/VWsM0YCL2iMoIJrbXje48lvIQAQ4p2ZA== "@types/node@^14.14.25": version "14.14.41" @@ -1770,13 +1787,6 @@ big.js@^6.1.1: resolved "https://registry.yarnpkg.com/big.js/-/big.js-6.1.1.tgz#63b35b19dc9775c94991ee5db7694880655d5537" integrity sha512-1vObw81a8ylZO5ePrtMay0n018TcftpTA5HFKDaSuiUDBo8biRBtjIobw60OpwuvrGk+FsxKamqN4cnmj/eXdg== -bigint-buffer@^1.1.5: - version "1.1.5" - resolved "https://registry.yarnpkg.com/bigint-buffer/-/bigint-buffer-1.1.5.tgz#d038f31c8e4534c1f8d0015209bf34b4fa6dd442" - integrity sha512-trfYco6AoZ+rKhKnxA0hgX0HAbVP/s808/EuDSe2JDzUnCp/xAsli35Orvk67UrTEcwuxZqYZDmfA2RXJgxVvA== - dependencies: - bindings "^1.3.0" - bignumber.js@^9.0.1: version "9.0.1" resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.0.1.tgz#8d7ba124c882bfd8e43260c67475518d0689e4e5" @@ -1787,13 +1797,6 @@ binary-extensions@^2.0.0: resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA== -bindings@^1.3.0: - version "1.5.0" - resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df" - integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ== - dependencies: - file-uri-to-path "1.0.0" - bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.11.9: version "4.12.0" resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88" @@ -2690,11 +2693,6 @@ dot-case@^3.0.4: no-case "^3.0.4" tslib "^2.0.3" -dotenv-expand@^5.1.0: - version "5.1.0" - resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-5.1.0.tgz#3fbaf020bfd794884072ea26b1e9791d45a629f0" - integrity sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA== - dotenv@10.0.0, dotenv@^10.0.0: version "10.0.0" resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81" @@ -3187,11 +3185,6 @@ file-entry-cache@^6.0.1: dependencies: flat-cache "^3.0.4" -file-uri-to-path@1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd" - integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw== - fill-range@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-4.0.0.tgz#d544811d428f98eb06a63dc402d2403c328c38f7" @@ -4097,9 +4090,9 @@ istanbul-reports@^3.0.2: istanbul-lib-report "^3.0.0" jayson@^3.4.4: - version "3.6.5" - resolved "https://registry.yarnpkg.com/jayson/-/jayson-3.6.5.tgz#e560bcad4daf098c7391f46ba8efc9d6f34a4102" - integrity sha512-wmOjX+eQcnCDyPF4KORomaIj9wj3h0B5VEbeD0+2VHfTfErB+h1zpR7oBkgCZp36AFjp3+a4CLz6U72BYpFHAw== + version "3.6.6" + resolved "https://registry.yarnpkg.com/jayson/-/jayson-3.6.6.tgz#189984f624e398f831bd2be8e8c80eb3abf764a1" + integrity sha512-f71uvrAWTtrwoww6MKcl9phQTC+56AopLyEenWvKVAIMz+q0oVGj6tenLZ7Z6UiPBkJtKLj4kt0tACllFQruGQ== dependencies: "@types/connect" "^3.4.33" "@types/express-serve-static-core" "^4.17.9" @@ -4114,7 +4107,7 @@ jayson@^3.4.4: isomorphic-ws "^4.0.1" json-stringify-safe "^5.0.1" lodash "^4.17.20" - uuid "^3.4.0" + uuid "^8.3.2" ws "^7.4.5" jest-changed-files@^26.6.2: @@ -6950,7 +6943,7 @@ string-similarity@^4.0.3: version "4.0.4" resolved "https://registry.yarnpkg.com/string-similarity/-/string-similarity-4.0.4.tgz#42d01ab0b34660ea8a018da8f56a3309bb8b2a5b" -string-width@^4.1.0, string-width@^4.2.0: +string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -7597,12 +7590,12 @@ util@0.12.4, util@^0.12.0: safe-buffer "^5.1.2" which-typed-array "^1.1.2" -uuid@^3.3.2, uuid@^3.4.0: +uuid@^3.3.2: version "3.4.0" resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== -uuid@^8.3.0: +uuid@^8.3.0, uuid@^8.3.2: version "8.3.2" resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== @@ -7801,9 +7794,9 @@ ws@^7.4.4: resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.5.tgz#a484dd851e9beb6fdb420027e3885e8ce48986c1" ws@^7.4.5: - version "7.5.5" - resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.5.tgz#8b4bc4af518cfabd0473ae4f99144287b33eb881" - integrity sha512-BAkMFcAzl8as1G/hArkxOxq3G7pjUqQ3gzYbLL0/5zNkph70e+lCoxBGnm6AW1+/aiNeV4fnKqZ8m4GZewmH2w== + version "7.5.6" + resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.6.tgz#e59fc509fb15ddfb65487ee9765c5a51dec5fe7b" + integrity sha512-6GLgCqo2cy2A2rjCNFlxQS6ZljG/coZfZXclldI8FB/1G3CCI36Zd8xy2HrFVACi8tfk5XrgLQEk+P0Tnz9UcA== xml-name-validator@^3.0.0: version "3.0.0" @@ -7843,10 +7836,10 @@ yargs-parser@^18.1.2: camelcase "^5.0.0" decamelize "^1.2.0" -yargs-parser@^20.2.2: - version "20.2.9" - resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee" - integrity sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w== +yargs-parser@^21.0.0: + version "21.0.0" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.0.0.tgz#a485d3966be4317426dd56bdb6a30131b281dc55" + integrity sha512-z9kApYUOCwoeZ78rfRYYWdiU/iNL6mwwYlkkZfJoyMR1xps+NEBX5X7XmRpxkZHhXJ6+Ey00IwKxBBSW9FIjyA== yargs@^15.4.1: version "15.4.1" @@ -7865,17 +7858,17 @@ yargs@^15.4.1: yargs-parser "^18.1.2" yargs@^17.0.1: - version "17.2.1" - resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.2.1.tgz#e2c95b9796a0e1f7f3bf4427863b42e0418191ea" - integrity sha512-XfR8du6ua4K6uLGm5S6fA+FIJom/MdJcFNVY8geLlp2v8GYbOXD4EB1tPNZsRn4vBzKGMgb5DRZMeWuFc2GO8Q== + version "17.3.0" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.3.0.tgz#295c4ffd0eef148ef3e48f7a2e0f58d0e4f26b1c" + integrity sha512-GQl1pWyDoGptFPJx9b9L6kmR33TGusZvXIZUT+BOz9f7X2L94oeAskFYLEg/FkhV06zZPBYLvLZRWeYId29lew== dependencies: cliui "^7.0.2" escalade "^3.1.1" get-caller-file "^2.0.5" require-directory "^2.1.1" - string-width "^4.2.0" + string-width "^4.2.3" y18n "^5.0.5" - yargs-parser "^20.2.2" + yargs-parser "^21.0.0" yn@3.1.1: version "3.1.1" From 6a9fe72d0b42feb2b704599fa8448553bd049a83 Mon Sep 17 00:00:00 2001 From: Riordan Panayides Date: Mon, 20 Dec 2021 17:37:46 +0000 Subject: [PATCH 7/7] Add mango group field and instruction serialisation --- .../Mango/MakeChangeMaxAccounts.tsx | 35 +++++++++++++------ utils/uiTypes/proposalCreationTypes.ts | 1 + 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/pages/dao/[symbol]/proposal/components/instructions/Mango/MakeChangeMaxAccounts.tsx b/pages/dao/[symbol]/proposal/components/instructions/Mango/MakeChangeMaxAccounts.tsx index cd5447ed23..643bd7ace6 100644 --- a/pages/dao/[symbol]/proposal/components/instructions/Mango/MakeChangeMaxAccounts.tsx +++ b/pages/dao/[symbol]/proposal/components/instructions/Mango/MakeChangeMaxAccounts.tsx @@ -13,10 +13,12 @@ import useGovernanceAssets from '@hooks/useGovernanceAssets' import { Governance, GovernanceAccountType } from '@models/accounts' import { ParsedAccount } from '@models/core/accounts' import useWalletStore from 'stores/useWalletStore' -//import { serializeInstructionToBase64 } from '@models/serialisation' +import { serializeInstructionToBase64 } from '@models/serialisation' import Input from '@components/inputs/Input' import GovernedAccountSelect from '../../GovernedAccountSelect' import { GovernedMultiTypeAccount } from '@utils/tokens' +import { makeChangeMaxMangoAccountsInstruction } from '@blockworks-foundation/mango-client' +import { BN } from '@project-serum/anchor' const MakeChangeMaxAccounts = ({ index, @@ -40,6 +42,7 @@ const MakeChangeMaxAccounts = ({ const [form, setForm] = useState({ governedAccount: undefined, programId: programId?.toString(), + mangoGroupKey: undefined, maxMangoAccounts: 1, }) const [formErrors, setFormErrors] = useState({}) @@ -63,16 +66,16 @@ const MakeChangeMaxAccounts = ({ wallet?.publicKey ) { //Mango instruction call and serialize - //example + const setMaxMangoAccountsInstr = makeChangeMaxMangoAccountsInstruction( + form.governedAccount.governance.info.governedAccount, + new PublicKey(form.mangoGroupKey!), + form.governedAccount.governance.pubkey, + new BN(form.maxMangoAccounts) + ) - // const upgradeIx = await createUpgradeInstruction( - // form.governedAccount.governance.info.governedAccount, - // new PublicKey(form.bufferAddress), - // form.governedAccount.governance.pubkey, - // wallet!.publicKey - // ) - // serializedInstruction = serializeInstructionToBase64(upgradeIx) - serializedInstruction = '' + serializedInstruction = serializeInstructionToBase64( + setMaxMangoAccountsInstr + ) } const obj: UiInstruction = { serializedInstruction: serializedInstruction, @@ -117,6 +120,18 @@ const MakeChangeMaxAccounts = ({ shouldBeGoverned={shouldBeGoverned} governance={governance} > + + handleSetForm({ + value: evt.target.value, + propertyName: 'mangoGroupKey', + }) + } + error={formErrors['mangoGroupKey']} + />