Skip to content

Commit

Permalink
fix signers in dual instructions (solana-labs#1738)
Browse files Browse the repository at this point in the history
  • Loading branch information
abrzezinski94 authored Aug 2, 2023
1 parent b0393aa commit e339dae
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 15 deletions.
18 changes: 14 additions & 4 deletions actions/createProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface InstructionDataWithHoldUpTime {
prerequisiteInstructions: TransactionInstruction[]
chunkBy?: number
signers?: Keypair[]
prerequisiteInstructionsSigners?: Keypair[]
prerequisiteInstructionsSigners?: (Keypair | null)[]
}

export class InstructionDataWithHoldUpTime {
Expand Down Expand Up @@ -75,7 +75,7 @@ export const createProposal = async (
const signatory = walletPubkey
const payer = walletPubkey
const prerequisiteInstructions: TransactionInstruction[] = []
const prerequisiteInstructionsSigners: Keypair[] = []
const prerequisiteInstructionsSigners: (Keypair | null)[] = []
// sum up signers
const signers: Keypair[] = instructionsData.flatMap((x) => x.signers ?? [])

Expand Down Expand Up @@ -203,14 +203,24 @@ export const createProposal = async (
deduplicateObjsFilter
)

const prerequisiteInstructionsChunks = chunks(
deduplicatedPrerequisiteInstructions,
lowestChunkBy
)

const prerequisiteInstructionsSignersChunks = chunks(
deduplicatedPrerequisiteInstructionsSigners,
lowestChunkBy
).filter((keypairArray) => keypairArray.filter((keypair) => keypair))

const signersSet = [
...chunks([...deduplicatedPrerequisiteInstructionsSigners], lowestChunkBy),
...prerequisiteInstructionsSignersChunks,
[],
...signerChunks,
]

const txes = [
...chunks(deduplicatedPrerequisiteInstructions, lowestChunkBy),
...prerequisiteInstructionsChunks,
instructions,
...insertChunks,
].map((txBatch, batchIdx) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React, { useContext, useEffect, useState } from 'react'
import React, { useContext, useEffect, useMemo, useState } from 'react'
import { ProgramAccount, Governance } from '@solana/spl-governance'
import {
UiInstruction,
Expand Down Expand Up @@ -43,7 +43,7 @@ const DualExercise = ({
setFormErrors({})
setForm({ ...form, [propertyName]: value })
}
const schema = getDualFinanceExerciseSchema()
const schema = useMemo(getDualFinanceExerciseSchema, [])
useEffect(() => {
function getInstruction(): Promise<UiInstruction> {
return getExerciseInstruction({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React, { useContext, useEffect, useState } from 'react'
import React, { useContext, useEffect, useState, useMemo } from 'react'
import { ProgramAccount, Governance } from '@solana/spl-governance'
import {
UiInstruction,
Expand Down Expand Up @@ -40,7 +40,7 @@ const DualWithdraw = ({
setFormErrors({})
setForm({ ...form, [propertyName]: value })
}
const schema = getDualFinanceWithdrawSchema()
const schema = useMemo(getDualFinanceWithdrawSchema, [])
useEffect(() => {
function getInstruction(): Promise<UiInstruction> {
return getWithdrawInstruction({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React, { useContext, useEffect, useState } from 'react'
import React, { useContext, useEffect, useState, useMemo } from 'react'
import { ProgramAccount, Governance } from '@solana/spl-governance'
import {
UiInstruction,
Expand Down Expand Up @@ -60,7 +60,7 @@ const InitStrike = ({
useEffect(() => {
setGovernedAccount(form.baseTreasury?.governance)
}, [form.baseTreasury])
const schema = getDualFinanceInitStrikeSchema()
const schema = useMemo(getDualFinanceInitStrikeSchema, [])

return (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React, { useContext, useEffect, useState } from 'react'
import React, { useContext, useEffect, useState, useMemo } from 'react'
import { ProgramAccount, Governance } from '@solana/spl-governance'
import {
UiInstruction,
Expand Down Expand Up @@ -62,7 +62,7 @@ const LiquidityStakingOption = ({
useEffect(() => {
setGovernedAccount(form.baseTreasury?.governance)
}, [form.baseTreasury])
const schema = getDualFinanceLiquidityStakingOptionSchema()
const schema = useMemo(getDualFinanceLiquidityStakingOptionSchema, [])

return (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React, { useContext, useEffect, useState } from 'react'
import React, { useContext, useEffect, useState, useMemo } from 'react'
import { ProgramAccount, Governance } from '@solana/spl-governance'
import {
UiInstruction,
Expand Down Expand Up @@ -47,7 +47,7 @@ const StakingOption = ({
setFormErrors({})
setForm({ ...form, [propertyName]: value })
}
const schema = getDualFinanceStakingOptionSchema()
const schema = useMemo(getDualFinanceStakingOptionSchema, [])
useEffect(() => {
function getInstruction(): Promise<UiInstruction> {
return getConfigInstruction({
Expand Down
2 changes: 1 addition & 1 deletion utils/uiTypes/proposalCreationTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface UiInstruction {
governance: ProgramAccount<Governance> | undefined
customHoldUpTime?: number
prerequisiteInstructions?: TransactionInstruction[]
prerequisiteInstructionsSigners?: Keypair[]
prerequisiteInstructionsSigners?: (Keypair | null)[]
chunkBy?: number
signers?: Keypair[]
}
Expand Down

0 comments on commit e339dae

Please sign in to comment.