upgrade spl-gov + fix big bg img (#1290)

* replace bg-desktop

* fix realm config decode

* fix

* add more env to gitignore

* upgrade spl-gov

* upgrade spl-gov

* upgrade configs for spl gov

* remove console log

* fix
This commit is contained in:
Adrian Brzeziński 2022-12-12 19:25:10 +01:00 committed by GitHub
parent 2345e16448
commit 719ca2f100
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 89 additions and 27 deletions

View File

@ -1,10 +0,0 @@
# Run in context of one realm: starts with default realm and disables realms page navigation
# REALM=MNGO
MAINNET_RPC=https://mango.rpcpool.com
DEVNET_RPC=https://mango.devnet.rpcpool.com
DEFAULT_GOVERNANCE_PROGRAM_ID=GTesTBiEWE32WHXXE2S4XbZvA5CrEc4xs6ZgRe895dP
NEXT_PUBLIC_API_ENDPOINT=http://localhost:3001/graphql
NEXT_PUBLIC_DISCORD_APPLICATION_CLIENT_ID=1042836142560645130
NEXT_PUBLIC_DISCORD_MATCHDAY_CLIENT_ID=1044361939322683442

1
.gitignore vendored
View File

@ -27,6 +27,7 @@ yarn-error.log*
# local env files
.env
.env.local
.env.development
.env.development.local
.env.test.local
.env.production.local

View File

@ -10,6 +10,8 @@ import {
getDaysFromTimestamp,
parseMintNaturalAmountFromDecimalAsBN,
fmtBnMintDecimalsUndelimited,
getHoursFromTimestamp,
getTimestampFromHours,
} from '@tools/sdk/units'
type FormErrors<T> = {
@ -27,7 +29,8 @@ export type BaseGovernanceFormFieldsV3 = {
minCommunityTokensToCreateProposal: string | 'disabled'
// 'disabled' for disabled values
minCouncilTokensToCreateProposal: string | 'disabled'
votingCoolOffTime: string
depositExemptProposalCount: string
communityVoteThreshold: string | 'disabled'
communityVetoVoteThreshold: string | 'disabled'
councilVoteThreshold: string | 'disabled'
@ -69,6 +72,8 @@ export const transformerGovernanceConfig_2_BaseGovernanceFormFieldsV3 = (
x.type === VoteThresholdType.Disabled ? 'disabled' : x.value!.toString(),
communityVoteTipping: (x) => x,
councilVoteTipping: (x) => x,
votingCoolOffTime: (x) => getHoursFromTimestamp(x).toString(),
depositExemptProposalCount: (x) => x.toString(),
_programVersion: (x) => x,
})
@ -107,6 +112,8 @@ export const transformerBaseGovernanceFormFieldsV3_2_GovernanceConfig = (
: { type: VoteThresholdType.YesVotePercentage, value: parseInt(x) },
communityVoteTipping: (x) => x,
councilVoteTipping: (x) => x,
votingCoolOffTime: (x) => getTimestampFromHours(parseFloat(x)),
depositExemptProposalCount: (x) => parseFloat(x),
_programVersion: (x) => x,
})

View File

@ -107,6 +107,36 @@ export const BaseGovernanceFormV3 = ({
}
error={formErrors['maxVotingTime']}
/>
<Input
label="Proposal Cool-off Time (hours)"
value={form.votingCoolOffTime}
name="votingCoolOffTime"
type="number"
min={0}
onChange={(evt) =>
setForm((prev) => ({
...prev,
votingCoolOffTime:
evt.target.value !== '' ? evt.target.value : '0',
}))
}
error={formErrors['votingCoolOffTime']}
/>
<Input
label="Deposit Exempt Proposal Count"
value={form.depositExemptProposalCount}
name="depositExemptProposalCount"
type="number"
min={0}
onChange={(evt) =>
setForm((prev) => ({
...prev,
depositExemptProposalCount:
evt.target.value !== '' ? evt.target.value : '0',
}))
}
error={formErrors['depositExemptProposalCount']}
/>
{(['community', 'council'] as const).map((govPop) => {
const capitalized = govPop === 'community' ? 'Community' : 'Council'
const minProposalTokensEnabled =

View File

@ -26,6 +26,7 @@ import {
fmtBNAmount,
fmtMintAmount,
getDaysFromTimestamp,
getHoursFromTimestamp,
} from '@tools/sdk/units'
import { dryRunInstruction } from 'actions/dryRunInstruction'
import { tryGetMint } from '../../../utils/tokens'
@ -133,6 +134,14 @@ export const GOVERNANCE_INSTRUCTIONS = {
<p>
{`maxVotingTime:
${getDaysFromTimestamp(args.config.maxVotingTime)} days(s)`}
</p>
<p>
{`votingCoolOffTime:
${getHoursFromTimestamp(args.config.votingCoolOffTime)} hour(s)`}
</p>
<p>
{`depositExemptProposalCount:
${args.config.depositExemptProposalCount}`}
</p>
<p>
{`communityVoteTipping:
@ -490,7 +499,7 @@ export const GOVERNANCE_INSTRUCTIONS = {
{`useCommunityVoterWeightAddin:
${
!!args.configArgs.useCommunityVoterWeightAddin ||
!!args.configArgs.communityTokenConfigArgs.useVoterWeightAddin
!!args.configArgs.communityTokenConfigArgs?.useVoterWeightAddin
}`}
</p>
<p>
@ -498,7 +507,7 @@ export const GOVERNANCE_INSTRUCTIONS = {
${
!!args.configArgs.useMaxCommunityVoterWeightAddin ||
!!args.configArgs.communityTokenConfigArgs
.useMaxVoterWeightAddin
?.useMaxVoterWeightAddin
}`}
</p>
<p>

View File

@ -112,7 +112,7 @@ export const assembleWallets = async (
if (!walletMap[walletAddress].stats.votingProposalCount) {
walletMap[walletAddress].stats.votingProposalCount =
account.governance.account.votingProposalCount || 0
account.governance.account.activeProposalCount.toNumber() || 0
}
// We're going to handle NFTs & programs specially

View File

@ -82,7 +82,7 @@
"@solana-mobile/wallet-adapter-mobile": "0.9.7",
"@solana/buffer-layout": "4.0.0",
"@solana/governance-program-library": "npm:@civic/governance-program-library@0.16.9-beta.2",
"@solana/spl-governance": "0.3.17",
"@solana/spl-governance": "0.3.18",
"@solana/spl-token": "0.1.8",
"@solana/spl-token-registry": "0.2.3775",
"@solana/wallet-adapter-backpack": "0.1.0",

View File

@ -1,5 +1,5 @@
import useRealm from '@hooks/useRealm'
import { fmtMintAmount } from '@tools/sdk/units'
import { fmtMintAmount, getHoursFromTimestamp } from '@tools/sdk/units'
import { DISABLED_VOTER_WEIGHT } from '@tools/constants'
import {
getFormattedStringFromDays,
@ -8,10 +8,11 @@ import {
import Button from '@components/Button'
import { VoteTipping } from '@solana/spl-governance'
import { AddressField, NumberField } from '../index'
import useProgramVersion from '@hooks/useProgramVersion'
const ParamsView = ({ activeGovernance, openGovernanceProposalModal }) => {
const { realm, mint, councilMint, ownVoterWeight } = useRealm()
const programVersion = useProgramVersion()
const realmAccount = realm?.account
const communityMint = realmAccount?.communityMint.toBase58()
@ -65,12 +66,22 @@ const ParamsView = ({ activeGovernance, openGovernanceProposalModal }) => {
padding
val={activeGovernance.account.config.minInstructionHoldUpTime}
/>
{/* NOT NEEDED RIGHT NOW */}
{/* <AddressField
label="Proposal Cool-off Time"
padding
val={activeGovernance.account.config.proposalCoolOffTime}
/> */}
{programVersion >= 3 && (
<>
<AddressField
label="Proposal Cool-off Time"
padding
val={`${getHoursFromTimestamp(
activeGovernance.account.config.votingCoolOffTime
)} hour(s)`}
/>
<AddressField
label="Deposit Exempt Proposal Count"
padding
val={`${activeGovernance.account.config.depositExemptProposalCount}`}
/>
</>
)}
<AddressField
label="Vote Threshold Percentage"
padding

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 MiB

After

Width:  |  Height:  |  Size: 393 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 83 KiB

View File

@ -309,6 +309,8 @@ export async function prepareRealmCreation({
councilVoteThreshold: councilVoteThreshold,
councilVetoVoteThreshold: councilVetoVoteThreshold,
communityVetoVoteThreshold: communityVetoVoteThreshold,
votingCoolOffTime: 0,
depositExemptProposalCount: 10,
})
const communityMintGovPk = createCommunityMintGovernance

View File

@ -9,10 +9,18 @@ export function getDaysFromTimestamp(unixTimestamp: number) {
return unixTimestamp / SECONDS_PER_DAY
}
export function getHoursFromTimestamp(unixTimestamp: number) {
return unixTimestamp / (60 * 60)
}
export function getTimestampFromDays(days: number) {
return days * SECONDS_PER_DAY
}
export function getTimestampFromHours(hours: number) {
return hours * 60 * 60
}
export function fmtBnMintDecimals(amount: BN, decimals: number) {
return new BigNumber(amount.toString()).shiftedBy(-decimals).toFormat()
}

View File

@ -27,6 +27,8 @@ export interface GovernanceConfigValues {
voteThresholdPercentage: number
mintDecimals: number
voteTipping?: VoteTipping
votingCoolOffTime?: number
depositExemptProposalCount?: number
}
// Parses min tokens to create (proposal or governance)
@ -79,6 +81,8 @@ export function getGovernanceConfigFromV2Form(
councilVoteThreshold: councilVoteThreshold,
councilVetoVoteThreshold: councilVetoVoteThreshold,
communityVetoVoteThreshold: communityVetoVoteThreshold,
votingCoolOffTime: values.votingCoolOffTime || 0,
depositExemptProposalCount: values.votingCoolOffTime || 10,
})
}

View File

@ -4257,10 +4257,10 @@
bs58 "^4.0.1"
superstruct "^0.15.2"
"@solana/spl-governance@0.3.17":
version "0.3.17"
resolved "https://registry.yarnpkg.com/@solana/spl-governance/-/spl-governance-0.3.17.tgz#ec6fc9c3e3c2eb5de0c00ebc8c4d46f6e5a899e9"
integrity sha512-GdKBb9Hwzsu6X3Kn1SwKUuuo4cGG9cUCnlSE0JXeGOriFEVcQf3rcuUIOU7JbKcN1vIMyDyayE8p632EOgFprw==
"@solana/spl-governance@0.3.18":
version "0.3.18"
resolved "https://registry.yarnpkg.com/@solana/spl-governance/-/spl-governance-0.3.18.tgz#13a17c6344b196fa8303749b68e8fec2a0b1988a"
integrity sha512-7bHAiQkzpJS1FYMBMSoVMfUmVqTHV9I5kF4KbcUZaUe08sGPUTNeu/EXXQaQyoJLqlrSYRQWIq/ckLaA9YJzJg==
dependencies:
"@solana/web3.js" "^1.22.0"
axios "^1.1.3"