Skip to content

Commit 346747d

Browse files
committed
Address bigz comments
1 parent 995c599 commit 346747d

2 files changed

Lines changed: 105 additions & 35 deletions

File tree

programs/autocrat_v0/src/lib.rs

Lines changed: 92 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,24 @@ pub const MAX_BPS: u16 = 10_000;
4040

4141
#[account]
4242
pub struct DAO {
43+
// treasury needed even though DAO is PDA for this reason: https://solana.stackexchange.com/questions/7667/a-peculiar-problem-with-cpis
44+
pub treasury_pda_bump: u8,
45+
pub treasury: Pubkey,
4346
pub meta_mint: Pubkey,
4447
pub usdc_mint: Pubkey,
48+
pub proposal_count: u32,
49+
pub last_proposal_slot: u64,
4550
// the percentage, in basis points, the pass price needs to be above the
4651
// fail price in order for the proposal to pass
4752
pub pass_threshold_bps: u16,
48-
pub proposal_count: u32,
4953
// for anti-spam, proposers need to burn some SOL. the amount that they need
5054
// to burn is inversely proportional to the amount of time that has passed
5155
// since the last proposal.
5256
// burn_amount = base_lamport_burn - (lamport_burn_decay_per_slot * slots_passed)
53-
pub last_proposal_slot: u64,
5457
pub base_burn_lamports: u64,
5558
pub burn_decay_per_slot_lamports: u64,
5659
pub slots_per_proposal: u64,
5760
pub market_taker_fee: i64,
58-
// treasury needed even though DAO is PDA for this reason: https://solana.stackexchange.com/questions/7667/a-peculiar-problem-with-cpis
59-
pub treasury_pda_bump: u8,
60-
pub treasury: Pubkey,
6161
}
6262

6363
#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Eq)]
@@ -169,6 +169,10 @@ pub mod autocrat_v0 {
169169
openbook_pass_market.quote_lot_size == 100, // you can quote META in increments of a hundredth of a penny
170170
AutocratError::InvalidMarket
171171
);
172+
require!(
173+
openbook_pass_market.collect_fee_admin == dao.treasury,
174+
AutocratError::InvalidMarket
175+
);
172176

173177
require!(
174178
openbook_fail_market.base_mint
@@ -204,6 +208,10 @@ pub mod autocrat_v0 {
204208
openbook_pass_market.quote_lot_size == 100,
205209
AutocratError::InvalidMarket
206210
);
211+
require!(
212+
openbook_fail_market.collect_fee_admin == dao.treasury,
213+
AutocratError::InvalidMarket
214+
);
207215
let clock = Clock::get()?;
208216

209217
let openbook_twap_pass_market = &ctx.accounts.openbook_twap_pass_market;
@@ -380,45 +388,86 @@ pub mod autocrat_v0 {
380388
Ok(())
381389
}
382390

383-
pub fn set_pass_threshold_bps(ctx: Context<Auth>, pass_threshold_bps: u16) -> Result<()> {
384-
let dao = &mut ctx.accounts.dao;
391+
// pub fn set_pass_threshold_bps(ctx: Context<Auth>, pass_threshold_bps: u16) -> Result<()> {
392+
// let dao = &mut ctx.accounts.dao;
385393

386-
dao.pass_threshold_bps = pass_threshold_bps;
394+
// dao.pass_threshold_bps = pass_threshold_bps;
387395

388-
Ok(())
389-
}
396+
// Ok(())
397+
// }
390398

391-
pub fn set_base_burn_lamports(ctx: Context<Auth>, base_burn_lamports: u64) -> Result<()> {
392-
let dao = &mut ctx.accounts.dao;
399+
// pub fn set_base_burn_lamports(ctx: Context<Auth>, base_burn_lamports: u64) -> Result<()> {
400+
// let dao = &mut ctx.accounts.dao;
393401

394-
dao.base_burn_lamports = base_burn_lamports;
402+
// dao.base_burn_lamports = base_burn_lamports;
395403

396-
Ok(())
397-
}
404+
// Ok(())
405+
// }
398406

399-
pub fn set_burn_decay_per_slot_lamports(
400-
ctx: Context<Auth>,
401-
burn_decay_per_slot_lamports: u64,
402-
) -> Result<()> {
403-
let dao = &mut ctx.accounts.dao;
407+
// pub fn set_burn_decay_per_slot_lamports(
408+
// ctx: Context<Auth>,
409+
// burn_decay_per_slot_lamports: u64,
410+
// ) -> Result<()> {
411+
// let dao = &mut ctx.accounts.dao;
404412

405-
dao.burn_decay_per_slot_lamports = burn_decay_per_slot_lamports;
413+
// dao.burn_decay_per_slot_lamports = burn_decay_per_slot_lamports;
406414

407-
Ok(())
408-
}
415+
// Ok(())
416+
// }
409417

410-
pub fn set_slots_per_proposal(ctx: Context<Auth>, slots_per_proposal: u64) -> Result<()> {
411-
let dao = &mut ctx.accounts.dao;
418+
// pub fn set_slots_per_proposal(ctx: Context<Auth>, slots_per_proposal: u64) -> Result<()> {
419+
// let dao = &mut ctx.accounts.dao;
412420

413-
dao.slots_per_proposal = slots_per_proposal;
421+
// dao.slots_per_proposal = slots_per_proposal;
414422

415-
Ok(())
423+
// Ok(())
424+
// }
425+
426+
// pub fn set_market_taker_fee(ctx: Context<Auth>, market_taker_fee: i64) -> Result<()> {
427+
// let dao = &mut ctx.accounts.dao;
428+
429+
// dao.market_taker_fee = market_taker_fee;
430+
431+
// Ok(())
432+
// }
433+
434+
#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize)]
435+
pub enum Test {
436+
Boo,
437+
Foo,
416438
}
417439

418-
pub fn set_market_taker_fee(ctx: Context<Auth>, market_taker_fee: i64) -> Result<()> {
440+
#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, Eq, PartialEq, Debug)]
441+
pub struct Testy {
442+
pub thing: Option<u64>,
443+
}
444+
445+
446+
pub fn update_dao(
447+
ctx: Context<UpdateDao>,
448+
dao_params: UpdateDaoParams,
449+
) -> Result<()> {
419450
let dao = &mut ctx.accounts.dao;
420451

421-
dao.market_taker_fee = market_taker_fee;
452+
if let Some(pass_threshold_bps) = dao_params.pass_threshold_bps {
453+
dao.pass_threshold_bps = pass_threshold_bps;
454+
}
455+
456+
if let Some(base_burn_lamports) = dao_params.base_burn_lamports {
457+
dao.base_burn_lamports = base_burn_lamports;
458+
}
459+
460+
if let Some(burn_decay_per_slot_lamports) = dao_params.burn_decay_per_slot_lamports {
461+
dao.burn_decay_per_slot_lamports = burn_decay_per_slot_lamports;
462+
}
463+
464+
if let Some(slots_per_proposal) = dao_params.slots_per_proposal {
465+
dao.slots_per_proposal = slots_per_proposal;
466+
}
467+
468+
if let Some(market_taker_fee) = dao_params.market_taker_fee {
469+
dao.market_taker_fee = market_taker_fee;
470+
}
422471

423472
Ok(())
424473
}
@@ -513,11 +562,24 @@ pub struct FinalizeProposal<'info> {
513562
pub dao_treasury: UncheckedAccount<'info>,
514563
}
515564

565+
#[derive(Debug, Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Eq)]
566+
pub struct UpdateDaoParams {
567+
pub pass_threshold_bps: Option<u16>,
568+
pub base_burn_lamports: Option<u64>,
569+
pub burn_decay_per_slot_lamports: Option<u64>,
570+
pub slots_per_proposal: Option<u64>,
571+
pub market_taker_fee: Option<i64>,
572+
}
573+
516574
#[derive(Accounts)]
517-
pub struct Auth<'info> {
575+
pub struct UpdateDao<'info> {
518576
#[account(mut)]
519577
pub dao: Account<'info, DAO>,
520578
/// CHECK: never read
579+
#[account(
580+
seeds = [dao.key().as_ref()],
581+
bump = dao.treasury_pda_bump,
582+
)]
521583
pub dao_treasury: Signer<'info>,
522584
}
523585

tests/autocratV0.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,14 @@ describe("autocrat_v0", async function () {
219219
isWritable: true,
220220
},
221221
];
222-
const data = autocrat.coder.instruction.encode("set_pass_threshold_bps", {
223-
passThresholdBps: 1000,
222+
const data = autocrat.coder.instruction.encode("update_dao", {
223+
daoParams: {
224+
passThresholdBps: 500,
225+
baseBurnLamports: null,
226+
burnDecayPerSlotLamports: null,
227+
slotsPerProposal: null,
228+
marketTakerFee: null,
229+
}
224230
});
225231
const instruction = {
226232
programId: autocrat.programId,
@@ -1136,7 +1142,7 @@ describe("autocrat_v0", async function () {
11361142
daoTreasury,
11371143
})
11381144
.remainingAccounts(
1139-
autocrat.instruction.setPassThresholdBps
1145+
autocrat.instruction.updateDao
11401146
.accounts({
11411147
dao,
11421148
daoTreasury,
@@ -1447,7 +1453,8 @@ async function initializeProposal(
14471453
null,
14481454
openbookTwapPassMarket,
14491455
{ confFilter: 0.1, maxStalenessSlots: 100 },
1450-
openbookPassMarketKP
1456+
openbookPassMarketKP,
1457+
daoTreasury
14511458
);
14521459

14531460
await openbookTwap.methods
@@ -1484,7 +1491,8 @@ async function initializeProposal(
14841491
null,
14851492
openbookTwapFailMarket,
14861493
{ confFilter: 0.1, maxStalenessSlots: 100 },
1487-
openbookFailMarketKP
1494+
openbookFailMarketKP,
1495+
daoTreasury
14881496
);
14891497
await openbookTwap.methods
14901498
.createTwapMarket(new BN(1000))

0 commit comments

Comments
 (0)