Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/solana-labs/governance-ui i…
Browse files Browse the repository at this point in the history
…nto solana-labs-main
  • Loading branch information
cctdaniel committed May 4, 2022
2 parents eca539f + 7c543ef commit 2fa13b0
Show file tree
Hide file tree
Showing 143 changed files with 6,877 additions and 3,290 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"cSpell.words": ["Addin", "blockworks", "solana"]
"cSpell.words": ["Addin", "blockworks", "lamports", "solana"]
}
44 changes: 20 additions & 24 deletions NftVotePlugin/sdk/accounts.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PublicKey } from '@solana/web3.js'

export const unusedMintPk = '11111111111111111111111111111111'
export const emptyPk = '11111111111111111111111111111111'

export const getNftRegistrarPDA = async (
realmPk: PublicKey,
Expand All @@ -22,17 +22,15 @@ export const getNftMaxVoterWeightRecord = async (
mint: PublicKey,
clientProgramId: PublicKey
) => {
const [
maxVoterWeightRecord,
maxVoterWeightRecordBump,
] = await PublicKey.findProgramAddress(
[
Buffer.from('max-voter-weight-record'),
realmPk.toBuffer(),
mint.toBuffer(),
],
clientProgramId
)
const [maxVoterWeightRecord, maxVoterWeightRecordBump] =
await PublicKey.findProgramAddress(
[
Buffer.from('max-voter-weight-record'),
realmPk.toBuffer(),
mint.toBuffer(),
],
clientProgramId
)
return {
maxVoterWeightRecord,
maxVoterWeightRecordBump,
Expand All @@ -45,18 +43,16 @@ export const getNftVoterWeightRecord = async (
walletPk: PublicKey,
clientProgramId: PublicKey
) => {
const [
voterWeightPk,
voterWeightRecordBump,
] = await PublicKey.findProgramAddress(
[
Buffer.from('voter-weight-record'),
realmPk.toBuffer(),
mint.toBuffer(),
walletPk.toBuffer(),
],
clientProgramId
)
const [voterWeightPk, voterWeightRecordBump] =
await PublicKey.findProgramAddress(
[
Buffer.from('voter-weight-record'),
realmPk.toBuffer(),
mint.toBuffer(),
walletPk.toBuffer(),
],
clientProgramId
)
return {
voterWeightPk,
voterWeightRecordBump,
Expand Down
9 changes: 6 additions & 3 deletions NftVotePlugin/store/nftPluginStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ const useNftPluginStore = create<nftPluginStore>((set, _get) => ({
})
},
setVotingNfts: (nfts, votingClient, nftMintRegistrar) => {
votingClient._setCurrentVoterNfts(nfts)
const filteredNfts = nfts.filter(
(x) => x.token.account.amount.cmpn(1) === 0
)
votingClient._setCurrentVoterNfts(filteredNfts)
set((s) => {
s.state.votingNfts = nfts
s.state.votingNfts = filteredNfts
})
_get().setVotingPower(nfts, nftMintRegistrar)
_get().setVotingPower(filteredNfts, nftMintRegistrar)
},
setVotingPower: (nfts, nftMintRegistrar) => {
const votingPower = nfts
Expand Down
19 changes: 9 additions & 10 deletions Strategies/components/MangoDepositComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,10 @@ const MangoDepositComponent = ({
symbol,
} = useRealm()
const [isDepositing, setIsDepositing] = useState(false)
const [
selectedMangoAccount,
setSelectedMangoAccount,
] = useState<MangoAccount | null>(
mangoAccounts.length ? mangoAccounts[0] : null
)
const [selectedMangoAccount, setSelectedMangoAccount] =
useState<MangoAccount | null>(
mangoAccounts.length ? mangoAccounts[0] : null
)
const [voteByCouncil, setVoteByCouncil] = useState(false)
const client = useVotePluginsClientStore(
(s) => s.state.currentRealmVotingClient
Expand Down Expand Up @@ -161,9 +159,10 @@ const MangoDepositComponent = ({
)
}

const minRentAmount = await connection.current.getMinimumBalanceForRentExemption(
MangoAccountLayout.span
)
const minRentAmount =
await connection.current.getMinimumBalanceForRentExemption(
MangoAccountLayout.span
)

const transferIx = SystemProgram.transfer({
fromPubkey: wallet!.publicKey!,
Expand Down Expand Up @@ -220,7 +219,7 @@ const MangoDepositComponent = ({
},
realm!,
governedTokenAccount!,
ownTokenRecord.pubkey,
ownTokenRecord,
defaultProposalMint!,
governedTokenAccount!.governance!.account!.proposalCount,
prerequisiteInstructions,
Expand Down
2 changes: 2 additions & 0 deletions Strategies/protocols/foresight/tools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const FORESIGHT_MINT_DEVNET =
'H7uqouPsJkeEiLpCEoC1qYVVquDrZan6ZfdPK2gS44zm'
18 changes: 9 additions & 9 deletions Strategies/protocols/mango/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ export const calculateAllDepositsInMangoAccountsForMint = (
) => {
let deposited = 0
const group = market!.group
const depositIndex = group?.tokens.findIndex(
(x) => x.mint.toBase58() === mint.toBase58()
)
const depositIndex =
mint &&
group?.tokens.findIndex((x) => x.mint.toBase58() === mint.toBase58())
if (accounts?.length && typeof depositIndex !== 'undefined' && group) {
const depositsWithAmountHiherThenZero = accounts
.map((x) => x.deposits[depositIndex])
Expand Down Expand Up @@ -211,8 +211,8 @@ const HandleMangoDeposit: HandleCreateProposalWithStrategy = async (
)
)
),
holdUpTime: matchedTreasury.governance!.account!.config
.minInstructionHoldUpTime,
holdUpTime:
matchedTreasury.governance!.account!.config.minInstructionHoldUpTime,
prerequisiteInstructions: [],
chunkSplitByDefault: true,
}
Expand All @@ -230,8 +230,8 @@ const HandleMangoDeposit: HandleCreateProposalWithStrategy = async (
data: getInstructionDataFromBase64(
serializeInstructionToBase64(createMangoAccountIns)
),
holdUpTime: matchedTreasury.governance!.account!.config
.minInstructionHoldUpTime,
holdUpTime:
matchedTreasury.governance!.account!.config.minInstructionHoldUpTime,
prerequisiteInstructions: [...prerequisiteInstructions],
splitToChunkByDefault: true,
}
Expand All @@ -249,8 +249,8 @@ const HandleMangoDeposit: HandleCreateProposalWithStrategy = async (
data: getInstructionDataFromBase64(
serializeInstructionToBase64(delegateMangoAccount)
),
holdUpTime: matchedTreasury.governance!.account!.config
.minInstructionHoldUpTime,
holdUpTime:
matchedTreasury.governance!.account!.config.minInstructionHoldUpTime,
prerequisiteInstructions: [],
splitToChunkByDefault: true,
}
Expand Down
9 changes: 7 additions & 2 deletions Strategies/types/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { MangoAccount } from '@blockworks-foundation/mango-client'
import { ProgramAccount, Realm, RpcContext } from '@solana/spl-governance'
import {
ProgramAccount,
Realm,
RpcContext,
TokenOwnerRecord,
} from '@solana/spl-governance'
import { PublicKey, TransactionInstruction } from '@solana/web3.js'
import { VotingClient } from '@utils/uiTypes/VotePlugin'
import { AssetAccount } from '@utils/uiTypes/assets'
Expand Down Expand Up @@ -31,7 +36,7 @@ export type HandleCreateProposalWithStrategy = (
form: MNGODepositForm,
realm: ProgramAccount<Realm>,
treasuaryAccount: AssetAccount,
tokenOwnerRecord: PublicKey,
tokenOwnerRecord: ProgramAccount<TokenOwnerRecord>,
governingTokenMint: PublicKey,
proposalIndex: number,
prerequisiteInstructions: TransactionInstruction[],
Expand Down
14 changes: 7 additions & 7 deletions VoteStakeRegistry/actions/closeDeposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ export const closeDeposit = async ({
wallet!.publicKey!,
clientProgramId
)
instructions.push(
client!.program.instruction.closeDepositEntry(depositIndex, {
accounts: {
voter: voter,
voterAuthority: wallet!.publicKey!,
},
const closeDepositEntry = await client!.program.methods
.closeDepositEntry(depositIndex)
.accounts({
voter: voter,
voterAuthority: wallet!.publicKey!,
})
)
.instruction()
instructions.push(closeDepositEntry)

const transaction = new Transaction()
transaction.add(...instructions)
Expand Down
9 changes: 5 additions & 4 deletions VoteStakeRegistry/actions/getClawbackInstruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ export const getClawbackInstruction = async ({
true
)

const clawbackIx = client?.program.instruction.clawback(voterDepositIndex, {
accounts: {
const clawbackIx = await client?.program.methods
.clawback(voterDepositIndex)
.accounts({
registrar,
realmAuthority,
voter,
vault: voterATAPk,
destination,
tokenProgram: TOKEN_PROGRAM_ID,
},
})
})
.instruction()
return clawbackIx
}
54 changes: 27 additions & 27 deletions VoteStakeRegistry/actions/getGrantInstruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,32 +69,32 @@ export const getGrantInstruction = async ({
true
)

const grantIx = client?.program.instruction.grant(
voterBump,
voterWeightBump,
{ [lockupKind]: {} },
new BN(startTime),
lockupPeriod,
allowClawback,
new BN(amount),
{
accounts: {
registrar,
voter,
voterAuthority: toPk,
voterWeightRecord: voterWeightPk,
vault: voterATAPk,
depositToken: fromPk,
tokenAuthority: grantAuthority,
grantAuthority: toPk,
depositMint: grantMintPk,
payer: toPk,
systemProgram: systemProgram,
tokenProgram: TOKEN_PROGRAM_ID,
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
rent: SYSVAR_RENT_PUBKEY,
},
}
)
const grantIx = await client?.program.methods
.grant(
voterBump,
voterWeightBump,
{ [lockupKind]: {} },
new BN(startTime),
lockupPeriod,
allowClawback,
new BN(amount)
)
.accounts({
registrar,
voter,
voterAuthority: toPk,
voterWeightRecord: voterWeightPk,
vault: voterATAPk,
depositToken: fromPk,
tokenAuthority: grantAuthority,
grantAuthority: toPk,
depositMint: grantMintPk,
payer: toPk,
systemProgram: systemProgram,
tokenProgram: TOKEN_PROGRAM_ID,
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
rent: SYSVAR_RENT_PUBKEY,
})
.instruction()
return grantIx
}
Loading

0 comments on commit 2fa13b0

Please sign in to comment.