Skip to content

Commit

Permalink
disable buffer authority validation for program upgrade (#1851)
Browse files Browse the repository at this point in the history
  • Loading branch information
asktree authored Oct 3, 2023
1 parent 61d6c0a commit 936cb8b
Showing 1 changed file with 87 additions and 79 deletions.
166 changes: 87 additions & 79 deletions utils/validations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,16 @@ export const validateBuffer = async (
let buffer: ProgramBufferAccount

try {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
buffer = create(info.data.parsed, ProgramBufferAccount)
} catch {
throw 'Invalid program buffer account'
}

/*
if (buffer.info.authority?.toBase58() !== governedAccount.toBase58()) {
throw `Buffer authority must be set to governance account
${governedAccount.toBase58()}`
}
} */
})
} else {
throw 'Provided value is not a valid account address'
Expand Down Expand Up @@ -530,11 +531,7 @@ export const getDualFinanceGovernanceAirdropSchema = ({
})
}

export const getDualFinanceMerkleAirdropSchema = ({
form,
}: {
form: any
}) => {
export const getDualFinanceMerkleAirdropSchema = ({ form }: { form: any }) => {
return yup.object().shape({
root: yup
.string()
Expand Down Expand Up @@ -621,7 +618,7 @@ export const getDualFinanceLiquidityStakingOptionSchema = ({
'expiration',
'Expiration must be a future unix seconds timestamp',
function (val: number) {
const nowUnixMs = Date.now() / 1_000;
const nowUnixMs = Date.now() / 1_000
// Primary goal is to catch users inputting ms instead of sec.
if (val > nowUnixMs * 10) {
return this.createError({
Expand All @@ -636,23 +633,25 @@ export const getDualFinanceLiquidityStakingOptionSchema = ({
return true
}
),
numTokens: yup.number().typeError('Num tokens is required')
.test('amount', 'amount', async function (val: number) {
if (!form.baseTreasury) {
return this.createError({
message: `Please select a treasury`,
})
}
const numAtomsInTreasury = new BN(
form.baseTreasury.extensions.token.account.amount
).toNumber()
if (numAtomsInTreasury < val) {
return this.createError({
message: `Not enough tokens`,
})
}
return true
}),
numTokens: yup
.number()
.typeError('Num tokens is required')
.test('amount', 'amount', async function (val: number) {
if (!form.baseTreasury) {
return this.createError({
message: `Please select a treasury`,
})
}
const numAtomsInTreasury = new BN(
form.baseTreasury.extensions.token.account.amount
).toNumber()
if (numAtomsInTreasury < val) {
return this.createError({
message: `Not enough tokens`,
})
}
return true
}),
lotSize: yup.number().typeError('lotSize is required'),
baseTreasury: yup.object().typeError('baseTreasury is required'),
quoteTreasury: yup.object().typeError('quoteTreasury is required'),
Expand All @@ -664,29 +663,34 @@ export const getDualFinanceStakingOptionSchema = ({
form,
connection,
}: {
form: any,
form: any
connection: any
}) => {
return yup.object().shape({
soName: yup.string().required('Staking option name is required')
.test('is-not-too-long', 'soName too long', (value) =>
value !== undefined && value.length < 32
),
soName: yup
.string()
.required('Staking option name is required')
.test(
'is-not-too-long',
'soName too long',
(value) => value !== undefined && value.length < 32
),
userPk: yup
.string()
.test(
'is-valid-address1', 'Please enter a valid PublicKey',
'is-valid-address1',
'Please enter a valid PublicKey',
async function (userPk: string) {
if (!userPk || !validatePubkey(userPk)) {
return false;
return false
}

const pubKey = getValidatedPublickKey(userPk)
const account = await getValidateAccount(connection.current, pubKey)
if (!account) {
return false;
return false
}
return true;
return true
}
),
optionExpirationUnixSeconds: yup
Expand All @@ -696,7 +700,7 @@ export const getDualFinanceStakingOptionSchema = ({
'expiration',
'Expiration must be a future unix seconds timestamp',
function (val: number) {
const nowUnixMs = Date.now() / 1_000;
const nowUnixMs = Date.now() / 1_000
// Primary goal is to catch users inputting ms instead of sec.
if (val > nowUnixMs * 10) {
return this.createError({
Expand All @@ -711,23 +715,25 @@ export const getDualFinanceStakingOptionSchema = ({
return true
}
),
numTokens: yup.number().typeError('Num tokens is required')
.test('amount', 'amount', async function (val: number) {
if (!form.baseTreasury) {
return this.createError({
message: `Please select a treasury`,
})
}
const numAtomsInTreasury = new BN(
form.baseTreasury.extensions.token.account.amount
).toNumber()
if (numAtomsInTreasury < val) {
return this.createError({
message: `Not enough tokens`,
})
}
return true
}),
numTokens: yup
.number()
.typeError('Num tokens is required')
.test('amount', 'amount', async function (val: number) {
if (!form.baseTreasury) {
return this.createError({
message: `Please select a treasury`,
})
}
const numAtomsInTreasury = new BN(
form.baseTreasury.extensions.token.account.amount
).toNumber()
if (numAtomsInTreasury < val) {
return this.createError({
message: `Not enough tokens`,
})
}
return true
}),
strike: yup.number().typeError('Strike is required'),
lotSize: yup.number().typeError('lotSize is required'),
baseTreasury: yup.object().typeError('baseTreasury is required'),
Expand All @@ -736,24 +742,24 @@ export const getDualFinanceStakingOptionSchema = ({
})
}

export const getDualFinanceGsoSchema = ({
form,
}: {
form: any
}) => {
export const getDualFinanceGsoSchema = ({ form }: { form: any }) => {
return yup.object().shape({
soName: yup.string().required('Staking option name is required')
.test('is-not-too-long', 'soName too long', (value) =>
value !== undefined && value.length < 32
),
soName: yup
.string()
.required('Staking option name is required')
.test(
'is-not-too-long',
'soName too long',
(value) => value !== undefined && value.length < 32
),
optionExpirationUnixSeconds: yup
.number()
.typeError('Expiration is required')
.test(
'expiration',
'Expiration must be a future unix seconds timestamp',
function (val: number) {
const nowUnixMs = Date.now() / 1_000;
const nowUnixMs = Date.now() / 1_000
// Primary goal is to catch users inputting ms instead of sec.
if (val > nowUnixMs * 10) {
return this.createError({
Expand All @@ -768,23 +774,25 @@ export const getDualFinanceGsoSchema = ({
return true
}
),
numTokens: yup.number().typeError('Num tokens is required')
.test('amount', 'amount', async function (val: number) {
if (!form.baseTreasury) {
return this.createError({
message: `Please select a treasury`,
})
}
const numAtomsInTreasury = new BN(
form.baseTreasury.extensions.token.account.amount
).toNumber()
if (numAtomsInTreasury < val) {
return this.createError({
message: `Not enough tokens`,
})
}
return true
}),
numTokens: yup
.number()
.typeError('Num tokens is required')
.test('amount', 'amount', async function (val: number) {
if (!form.baseTreasury) {
return this.createError({
message: `Please select a treasury`,
})
}
const numAtomsInTreasury = new BN(
form.baseTreasury.extensions.token.account.amount
).toNumber()
if (numAtomsInTreasury < val) {
return this.createError({
message: `Not enough tokens`,
})
}
return true
}),
strike: yup.number().typeError('strike is required'),
lotSize: yup.number().typeError('lotSize is required'),
baseTreasury: yup.object().typeError('baseTreasury is required'),
Expand Down

1 comment on commit 936cb8b

@vercel
Copy link

@vercel vercel bot commented on 936cb8b Oct 3, 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-git-main-solana-labs.vercel.app
app.realms.today
governance-ui-solana-labs.vercel.app

Please sign in to comment.