Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable buffer authority validation for program upgrade #1851

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading