Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mango v4 create deposit delegate tweak #1915

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 @@
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,35 +36,108 @@
const getMangoAccounts = async () => {
const accounts = await mangoClient?.getMangoAccountsForOwner(
mangoGroup!,
account.extensions.transferAddress!
account.extensions.token!.account.owner!
)
if (accounts) {
setMangoAccounts(accounts)
}
}
getMangoAccounts()
}, [mangoClient !== null && mangoGroup !== null])

Check warning on line 46 in components/TreasuryAccount/MangoModal.tsx

View workflow job for this annotation

GitHub Actions / Run Tests

React Hook useEffect has missing dependencies: 'account.extensions.token', 'mangoClient', and 'mangoGroup'. Either include them or remove the dependency array

Check warning on line 46 in components/TreasuryAccount/MangoModal.tsx

View workflow job for this annotation

GitHub Actions / Run Tests

React Hook useEffect has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked
const handleCreateAccount = async () => {
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 @@
title: proposalTitle,
description: proposalDescription,
voteByCouncil,
instructionsData: [instructionData],
instructionsData: [
createAccInstData,
depositAccInstData,
delegateAccInstData,
],
governance: account.governance!,
})
const url = fmtUrlWithCluster(
Expand All @@ -87,6 +166,7 @@
<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 @@ -1311,6 +1311,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,
// },
]
Loading