Skip to content

Commit 4652e7e

Browse files
committed
Parametrize slots_per_proposal
1 parent 627d7dd commit 4652e7e

3 files changed

Lines changed: 50 additions & 28 deletions

File tree

programs/autocrat_v0/src/lib.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ security_txt! {
2626

2727
declare_id!("meta3cxKzFBmWYgCVozmvCQAS3y9b3fGxrG9HkHL7Wi");
2828

29+
pub const SLOTS_PER_10_SECS: u64 = 25;
30+
pub const THREE_DAYS_IN_SLOTS: u64 = 5 * 24 * 60 * 6 * SLOTS_PER_10_SECS;
31+
2932
// by default, the pass price needs to be 5% higher than the fail price
3033
pub const DEFAULT_PASS_THRESHOLD_BPS: u16 = 500;
3134

@@ -34,8 +37,6 @@ pub const DEFAULT_BASE_BURN_LAMPORTS: u64 = 50 * solana_program::native_token::L
3437
pub const DEFAULT_BURN_DECAY_PER_SLOT_LAMPORTS: u64 = 46_300;
3538

3639
pub const MAX_BPS: u16 = 10_000;
37-
pub const SLOTS_PER_10_SECS: u64 = 25;
38-
pub const TEN_DAYS_IN_SLOTS: u64 = 10 * 24 * 60 * 6 * SLOTS_PER_10_SECS;
3940

4041
#[account]
4142
pub struct DAO {
@@ -52,6 +53,7 @@ pub struct DAO {
5253
pub last_proposal_slot: u64,
5354
pub base_burn_lamports: u64,
5455
pub burn_decay_per_slot_lamports: u64,
56+
pub slots_per_proposal: u64,
5557
// treasury needed even though DAO is PDA for this reason: https://solana.stackexchange.com/questions/7667/a-peculiar-problem-with-cpis
5658
pub treasury_pda_bump: u8,
5759
pub treasury: Pubkey,
@@ -104,9 +106,12 @@ pub mod autocrat_v0 {
104106
dao.meta_mint = ctx.accounts.meta_mint.key();
105107
dao.usdc_mint = ctx.accounts.usdc_mint.key();
106108

109+
dao.proposal_count = 1;
110+
107111
dao.pass_threshold_bps = DEFAULT_PASS_THRESHOLD_BPS;
108112
dao.base_burn_lamports = DEFAULT_BASE_BURN_LAMPORTS;
109113
dao.burn_decay_per_slot_lamports = DEFAULT_BURN_DECAY_PER_SLOT_LAMPORTS;
114+
dao.slots_per_proposal = THREE_DAYS_IN_SLOTS;
110115

111116
let (treasury_pubkey, treasury_bump) =
112117
Pubkey::find_program_address(&[dao.key().as_ref()], ctx.program_id);
@@ -281,7 +286,7 @@ pub mod autocrat_v0 {
281286
let clock = Clock::get()?;
282287

283288
require!(
284-
clock.slot >= proposal.slot_enqueued + TEN_DAYS_IN_SLOTS,
289+
clock.slot >= proposal.slot_enqueued + ctx.accounts.dao.slots_per_proposal,
285290
AutocratError::ProposalTooYoung
286291
);
287292

@@ -307,11 +312,11 @@ pub mod autocrat_v0 {
307312
openbook_twap_fail_market.twap_oracle.last_updated_slot - proposal.slot_enqueued;
308313

309314
require!(
310-
pass_market_slots_passed >= TEN_DAYS_IN_SLOTS,
315+
pass_market_slots_passed >= ctx.accounts.dao.slots_per_proposal,
311316
AutocratError::MarketsTooYoung
312317
);
313318
require!(
314-
fail_market_slots_passed >= TEN_DAYS_IN_SLOTS,
319+
fail_market_slots_passed >= ctx.accounts.dao.slots_per_proposal,
315320
AutocratError::MarketsTooYoung
316321
);
317322

@@ -396,6 +401,14 @@ pub mod autocrat_v0 {
396401

397402
Ok(())
398403
}
404+
405+
pub fn set_slots_per_proposal(ctx: Context<Auth>, slots_per_proposal: u64) -> Result<()> {
406+
let dao = &mut ctx.accounts.dao;
407+
408+
dao.slots_per_proposal = slots_per_proposal;
409+
410+
Ok(())
411+
}
399412
}
400413

401414
#[derive(Accounts)]

tests/autocratV0.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ const AUTOCRAT_MIGRATOR_PROGRAM_ID = new PublicKey(
8787
"8C4WEdr54tBPdtmeTPUBuZX5bgUMZw4XdvpNoNaQ6NwR"
8888
);
8989

90-
9190
describe("autocrat_v0", async function () {
9291
let provider,
9392
connection,
@@ -173,7 +172,6 @@ describe("autocrat_v0", async function () {
173172
autocrat.programId
174173
);
175174

176-
177175
await autocrat.methods
178176
.initializeDao()
179177
.accounts({
@@ -192,13 +190,23 @@ describe("autocrat_v0", async function () {
192190
const daoAcc = await autocrat.account.dao.fetch(dao);
193191
assert(daoAcc.metaMint.equals(META));
194192
assert(daoAcc.usdcMint.equals(USDC));
195-
assert.equal(daoAcc.proposalCount, 0);
193+
assert.equal(daoAcc.proposalCount, 1);
196194
assert.equal(daoAcc.passThresholdBps, 500);
197195
assert.ok(daoAcc.baseBurnLamports.eq(new BN(1_000_000_000).muln(50)));
198196
assert.ok(daoAcc.burnDecayPerSlotLamports.eq(new BN(46_300)));
199197

200-
treasuryMetaAccount = await createAssociatedTokenAccount(banksClient, payer, META, daoTreasury);
201-
treasuryUsdcAccount = await createAssociatedTokenAccount(banksClient, payer, USDC, daoTreasury);
198+
treasuryMetaAccount = await createAssociatedTokenAccount(
199+
banksClient,
200+
payer,
201+
META,
202+
daoTreasury
203+
);
204+
treasuryUsdcAccount = await createAssociatedTokenAccount(
205+
banksClient,
206+
payer,
207+
USDC,
208+
daoTreasury
209+
);
202210
});
203211
});
204212

@@ -278,7 +286,6 @@ describe("autocrat_v0", async function () {
278286
aliceQuoteFailConditionalTokenAccount,
279287
newPassThresholdBps,
280288
instruction;
281-
282289

283290
beforeEach(async function () {
284291
// const accounts = [
@@ -307,10 +314,21 @@ describe("autocrat_v0", async function () {
307314
await mintToOverride(context, treasuryUsdcAccount, 1_000_000n);
308315

309316
let receiver = Keypair.generate();
310-
let to0 = await createAccount(banksClient, payer, META, receiver.publicKey);
311-
let to1 = await createAccount(banksClient, payer, USDC, receiver.publicKey);
317+
let to0 = await createAccount(
318+
banksClient,
319+
payer,
320+
META,
321+
receiver.publicKey
322+
);
323+
let to1 = await createAccount(
324+
banksClient,
325+
payer,
326+
USDC,
327+
receiver.publicKey
328+
);
312329

313-
const ix = await migrator.methods.multiTransfer2()
330+
const ix = await migrator.methods
331+
.multiTransfer2()
314332
.accounts({
315333
authority: daoTreasury,
316334
from0: treasuryMetaAccount,
@@ -324,7 +342,7 @@ describe("autocrat_v0", async function () {
324342
programId: ix.programId,
325343
accounts: ix.keys,
326344
data: ix.data,
327-
}
345+
};
328346

329347
proposal = await initializeProposal(
330348
autocrat,
@@ -768,7 +786,7 @@ describe("autocrat_v0", async function () {
768786
// isWritable: false,
769787
// isSigner: false,
770788
// })
771-
instruction.accounts
789+
instruction.accounts
772790
.concat({
773791
pubkey: migrator.programId,
774792
isWritable: false,

tests/migrator.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ const { PublicKey, Keypair } = anchor.web3;
77

88
import { assert } from "chai";
99

10-
import {
11-
startAnchor,
12-
} from "solana-bankrun";
10+
import { startAnchor } from "solana-bankrun";
1311

1412
const AUTOCRAT_MIGRATOR_PROGRAM_ID = new PublicKey(
1513
"8C4WEdr54tBPdtmeTPUBuZX5bgUMZw4XdvpNoNaQ6NwR"
@@ -30,14 +28,7 @@ import {
3028
} from "spl-token-bankrun";
3129

3230
describe("autocrat_migrator", async function () {
33-
let provider,
34-
connection,
35-
migrator,
36-
payer,
37-
context,
38-
banksClient,
39-
META,
40-
USDC;
31+
let provider, connection, migrator, payer, context, banksClient, META, USDC;
4132

4233
before(async function () {
4334
context = await startAnchor("./", [], []);
@@ -113,7 +104,7 @@ describe("autocrat_migrator", async function () {
113104
to1,
114105
})
115106
.rpc();
116-
107+
117108
assert((await getAccount(banksClient, from0)).amount == 0n);
118109
assert((await getAccount(banksClient, from1)).amount == 0n);
119110

0 commit comments

Comments
 (0)