From 91210a1d859eae1d3a371e1d6330b77a93fb7589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Brzezin=CC=81ski?= Date: Sat, 11 Nov 2023 15:31:20 +0100 Subject: [PATCH] mango v4 create deposit delegate tweak --- components/TreasuryAccount/MangoModal.tsx | 100 ++++++++++++++++-- components/instructions/programs/mangoV4.tsx | 44 ++++++++ .../staticInvestments.ts | 26 ++--- 3 files changed, 147 insertions(+), 23 deletions(-) diff --git a/components/TreasuryAccount/MangoModal.tsx b/components/TreasuryAccount/MangoModal.tsx index 0f394df614..18316a40a5 100644 --- a/components/TreasuryAccount/MangoModal.tsx +++ b/components/TreasuryAccount/MangoModal.tsx @@ -3,6 +3,7 @@ import AdditionalProposalOptions from '@components/AdditionalProposalOptions' import Button from '@components/Button' import Input from '@components/inputs/Input' import Select from '@components/inputs/Select' +import { BN } from '@coral-xyz/anchor' import useCreateProposal from '@hooks/useCreateProposal' import UseMangoV4 from '@hooks/useMangoV4' import useQueryContext from '@hooks/useQueryContext' @@ -11,6 +12,7 @@ import { getInstructionDataFromBase64, serializeInstructionToBase64, } from '@solana/spl-governance' +import { AccountMeta, PublicKey } from '@solana/web3.js' import { AssetAccount } from '@utils/uiTypes/assets' import { useRouter } from 'next/router' import { useEffect, useState } from 'react' @@ -34,7 +36,7 @@ const MangoModal = ({ account }: { account: AssetAccount }) => { const getMangoAccounts = async () => { const accounts = await mangoClient?.getMangoAccountsForOwner( mangoGroup!, - account.extensions.transferAddress! + account.extensions.token!.account.owner! ) if (accounts) { setMangoAccounts(accounts) @@ -46,23 +48,96 @@ const MangoModal = ({ account }: { account: AssetAccount }) => { try { setIsProposing(true) const newAccountNum = getNextAccountNumber(mangoAccounts) - const ix = await mangoClient?.program.methods + const bank = mangoGroup!.getFirstBankByMint( + account.extensions.mint!.publicKey! + ) + const createAccIx = await mangoClient!.program.methods .accountCreate( newAccountNum, 8, - 8, - 8, - 8, + 4, + 4, + 32, mangoAccName || `Account ${newAccountNum + 1}` ) .accounts({ group: mangoGroup!.publicKey, - owner: account.extensions.transferAddress, - payer: account.extensions.transferAddress, + owner: account.extensions.token!.account.owner!, + payer: account.extensions.token!.account.owner!, + }) + .instruction() + + const acctNumBuffer = Buffer.alloc(4) + acctNumBuffer.writeUInt32LE(newAccountNum) + + const [mangoAccount] = PublicKey.findProgramAddressSync( + [ + Buffer.from('MangoAccount'), + mangoGroup!.publicKey.toBuffer(), + account.extensions.token!.account.owner!.toBuffer(), + acctNumBuffer, + ], + mangoClient!.programId + ) + + const depositIx = await mangoClient!.program.methods + .tokenDeposit(new BN(100000000000), false) + .accounts({ + group: mangoGroup!.publicKey, + account: mangoAccount, + owner: account.extensions.token!.account.owner!, + bank: bank.publicKey, + vault: bank.vault, + oracle: bank.oracle, + tokenAccount: account.pubkey, + tokenAuthority: account.extensions.token!.account.owner!, + }) + .remainingAccounts( + [bank.publicKey, bank.oracle].map( + (pk) => + ({ + pubkey: pk, + isWritable: false, + isSigner: false, + } as AccountMeta) + ) + ) + .instruction() + + const delegateIx = await mangoClient!.program.methods + .accountEdit( + null, + new PublicKey('EsWMqyaEDoAqMgiWG9McSmpetBiYjL4VkHPkfevxKu4D'), + null, + null + ) + .accounts({ + group: mangoGroup!.publicKey, + account: mangoAccount, + owner: account.extensions.token!.account.owner!, }) .instruction() - const instructionData = { - data: getInstructionDataFromBase64(serializeInstructionToBase64(ix!)), + + const createAccInstData = { + data: getInstructionDataFromBase64( + serializeInstructionToBase64(createAccIx!) + ), + holdUpTime: + account?.governance.account?.config.minInstructionHoldUpTime, + prerequisiteInstructions: [], + } + const depositAccInstData = { + data: getInstructionDataFromBase64( + serializeInstructionToBase64(depositIx!) + ), + holdUpTime: + account?.governance.account?.config.minInstructionHoldUpTime, + prerequisiteInstructions: [], + } + const delegateAccInstData = { + data: getInstructionDataFromBase64( + serializeInstructionToBase64(delegateIx!) + ), holdUpTime: account?.governance.account?.config.minInstructionHoldUpTime, prerequisiteInstructions: [], @@ -71,7 +146,11 @@ const MangoModal = ({ account }: { account: AssetAccount }) => { title: proposalTitle, description: proposalDescription, voteByCouncil, - instructionsData: [instructionData], + instructionsData: [ + createAccInstData, + depositAccInstData, + delegateAccInstData, + ], governance: account.governance!, }) const url = fmtUrlWithCluster( @@ -87,6 +166,7 @@ const MangoModal = ({ account }: { account: AssetAccount }) => {

Mango

+ {console.log(mangoAccount)} {mangoGroup && (