From 936cb8b2aeb1f982c091769fc8b3d412f67f2391 Mon Sep 17 00:00:00 2001 From: agrippa Date: Tue, 3 Oct 2023 17:13:15 -0400 Subject: [PATCH] disable buffer authority validation for program upgrade (#1851) --- utils/validations.tsx | 166 ++++++++++++++++++++++-------------------- 1 file changed, 87 insertions(+), 79 deletions(-) diff --git a/utils/validations.tsx b/utils/validations.tsx index eb9f152b03..4a3126d1cd 100644 --- a/utils/validations.tsx +++ b/utils/validations.tsx @@ -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' @@ -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() @@ -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({ @@ -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'), @@ -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 @@ -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({ @@ -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'), @@ -736,16 +742,16 @@ 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') @@ -753,7 +759,7 @@ export const getDualFinanceGsoSchema = ({ '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({ @@ -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'),