Skip to content

Commit

Permalink
mango v4 create deposit delegate tweak (#1915)
Browse files Browse the repository at this point in the history
  • Loading branch information
abrzezinski94 authored Nov 11, 2023
1 parent eebc0a7 commit 5ffea9d
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 23 deletions.
100 changes: 90 additions & 10 deletions components/TreasuryAccount/MangoModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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)
Expand All @@ -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: [],
Expand All @@ -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(
Expand All @@ -87,6 +166,7 @@ const MangoModal = ({ account }: { account: AssetAccount }) => {
<div>
<h3 className="mb-4 flex items-center">Mango</h3>
<div>
{console.log(mangoAccount)}
{mangoGroup && (
<Select
className="mb-3"
Expand Down
44 changes: 44 additions & 0 deletions components/instructions/programs/mangoV4.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,50 @@ const instructions = () => ({
}
},
},
117255: {
name: 'Token Deposit',
accounts: [
{ name: 'Group' },
{ name: 'Account' },
{ name: 'Owner' },
{ name: 'Payer' },
],
getDataUI: async (
connection: Connection,
data: Uint8Array
//accounts: AccountMetaData[]
) => {
const info = await displayArgs(connection, data)
try {
return <div>{info}</div>
} catch (e) {
console.log(e)
return <div>{JSON.stringify(data)}</div>
}
},
},
186211: {
name: 'Edit Mango Account',
accounts: [
{ name: 'Group' },
{ name: 'Account' },
{ name: 'Owner' },
{ name: 'Payer' },
],
getDataUI: async (
connection: Connection,
data: Uint8Array
//accounts: AccountMetaData[]
) => {
const info = await displayArgs(connection, data)
try {
return <div>{info}</div>
} catch (e) {
console.log(e)
return <div>{JSON.stringify(data)}</div>
}
},
},
})

export const MANGO_V4_INSTRUCTIONS = {
Expand Down
26 changes: 13 additions & 13 deletions hooks/useAccountInvestments/staticInvestments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,6 @@ export const getSolInvestments = () => [
strategyDescription: '',
createProposalFcn: () => null,
},
{
liquidity: 0,
protocolSymbol: '',
apy: '',
protocolName: 'Mango',
handledMint: '',
handledTokenSymbol: '',
handledTokenImgSrc: '',
protocolLogoSrc: 'https://alpha.mango.markets/logos/logo-mark.svg',
strategyName: 'Trade',
strategyDescription: '',
createProposalFcn: () => null,
},
]

export const getTokenInvestments = (tokenImg: string) => [
Expand All @@ -59,4 +46,17 @@ export const getTokenInvestments = (tokenImg: string) => [
createProposalFcn: () => null,
noProtocol: true,
},
// {
// liquidity: 0,
// protocolSymbol: '',
// apy: '',
// protocolName: 'Mango',
// handledMint: '',
// handledTokenSymbol: '',
// handledTokenImgSrc: tokenImg,
// protocolLogoSrc: 'https://alpha.mango.markets/logos/logo-mark.svg',
// strategyName: 'Trade',
// strategyDescription: '',
// createProposalFcn: () => null,
// },
]

1 comment on commit 5ffea9d

@vercel
Copy link

@vercel vercel bot commented on 5ffea9d Nov 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

governance-ui – ./

governance-ui-solana-labs.vercel.app
app.realms.today
governance-ui-git-main-solana-labs.vercel.app

Please sign in to comment.