Skip to content

Commit eaef2d5

Browse files
committed
Parametrize expected_value
1 parent 346747d commit eaef2d5

2 files changed

Lines changed: 19 additions & 67 deletions

File tree

programs/autocrat_v0/src/lib.rs

Lines changed: 10 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub struct DAO {
5858
pub burn_decay_per_slot_lamports: u64,
5959
pub slots_per_proposal: u64,
6060
pub market_taker_fee: i64,
61+
pub twap_expected_value: u64,
6162
}
6263

6364
#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Eq)]
@@ -114,6 +115,7 @@ pub mod autocrat_v0 {
114115
dao.burn_decay_per_slot_lamports = DEFAULT_BURN_DECAY_PER_SLOT_LAMPORTS;
115116
dao.slots_per_proposal = THREE_DAYS_IN_SLOTS;
116117
dao.market_taker_fee = 0;
118+
dao.twap_expected_value = 10_000; // 1 USDC per META
117119

118120
let (treasury_pubkey, treasury_bump) =
119121
Pubkey::find_program_address(&[dao.key().as_ref()], ctx.program_id);
@@ -226,11 +228,11 @@ pub mod autocrat_v0 {
226228
AutocratError::TWAPMarketTooOld
227229
);
228230
require!(
229-
openbook_twap_pass_market.twap_oracle.expected_value == 1000,
231+
openbook_twap_pass_market.twap_oracle.expected_value == dao.twap_expected_value,
230232
AutocratError::TWAPMarketInvalidExpectedValue
231233
);
232234
require!(
233-
openbook_twap_fail_market.twap_oracle.expected_value == 1000,
235+
openbook_twap_fail_market.twap_oracle.expected_value == dao.twap_expected_value,
234236
AutocratError::TWAPMarketInvalidExpectedValue
235237
);
236238

@@ -388,61 +390,6 @@ pub mod autocrat_v0 {
388390
Ok(())
389391
}
390392

391-
// pub fn set_pass_threshold_bps(ctx: Context<Auth>, pass_threshold_bps: u16) -> Result<()> {
392-
// let dao = &mut ctx.accounts.dao;
393-
394-
// dao.pass_threshold_bps = pass_threshold_bps;
395-
396-
// Ok(())
397-
// }
398-
399-
// pub fn set_base_burn_lamports(ctx: Context<Auth>, base_burn_lamports: u64) -> Result<()> {
400-
// let dao = &mut ctx.accounts.dao;
401-
402-
// dao.base_burn_lamports = base_burn_lamports;
403-
404-
// Ok(())
405-
// }
406-
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;
412-
413-
// dao.burn_decay_per_slot_lamports = burn_decay_per_slot_lamports;
414-
415-
// Ok(())
416-
// }
417-
418-
// pub fn set_slots_per_proposal(ctx: Context<Auth>, slots_per_proposal: u64) -> Result<()> {
419-
// let dao = &mut ctx.accounts.dao;
420-
421-
// dao.slots_per_proposal = slots_per_proposal;
422-
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,
438-
}
439-
440-
#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, Eq, PartialEq, Debug)]
441-
pub struct Testy {
442-
pub thing: Option<u64>,
443-
}
444-
445-
446393
pub fn update_dao(
447394
ctx: Context<UpdateDao>,
448395
dao_params: UpdateDaoParams,
@@ -469,6 +416,10 @@ pub mod autocrat_v0 {
469416
dao.market_taker_fee = market_taker_fee;
470417
}
471418

419+
if let Some(twap_expected_value) = dao_params.twap_expected_value {
420+
dao.twap_expected_value = twap_expected_value;
421+
}
422+
472423
Ok(())
473424
}
474425

@@ -569,6 +520,7 @@ pub struct UpdateDaoParams {
569520
pub burn_decay_per_slot_lamports: Option<u64>,
570521
pub slots_per_proposal: Option<u64>,
571522
pub market_taker_fee: Option<i64>,
523+
pub twap_expected_value: Option<u64>,
572524
}
573525

574526
#[derive(Accounts)]
@@ -620,7 +572,7 @@ pub enum AutocratError {
620572
InvalidMarket,
621573
#[msg("`TWAPMarket` must have an `initial_slot` within 50 slots of the proposal's `slot_enqueued`")]
622574
TWAPMarketTooOld,
623-
#[msg("`TWAPMarket` must have an expected value of 1000, or 0.1 USDC per META")]
575+
#[msg("`TWAPMarket` has the wrong `expected_value`")]
624576
TWAPMarketInvalidExpectedValue,
625577
#[msg("One of the vaults has an invalid `settlement_authority`")]
626578
InvalidSettlementAuthority,

tests/autocratV0.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ describe("autocrat_v0", async function () {
512512

513513
let passBuyArgs: PlaceOrderArgs = {
514514
side: Side.Bid,
515-
priceLots: new BN(1000), // 0.1 USDC for 1 META
515+
priceLots: new BN(10000), // 1 USDC for 1 META
516516
maxBaseLots: new BN(10),
517517
maxQuoteLotsIncludingFees: new BN(10000),
518518
clientOrderId: new BN(1),
@@ -523,7 +523,7 @@ describe("autocrat_v0", async function () {
523523
};
524524
let failBuyArgs: PlaceOrderArgs = {
525525
side: Side.Bid,
526-
priceLots: new BN(700), // 0.07 USDC for 1 META
526+
priceLots: new BN(7000), // 0.7 USDC for 1 META
527527
maxBaseLots: new BN(10),
528528
maxQuoteLotsIncludingFees: new BN(10000),
529529
clientOrderId: new BN(1),
@@ -535,7 +535,7 @@ describe("autocrat_v0", async function () {
535535

536536
let passSellArgs: PlaceOrderArgs = {
537537
side: Side.Ask,
538-
priceLots: new BN(1100), // 0.11 USDC for 1 META
538+
priceLots: new BN(11_000), // 1.1 USDC for 1 META
539539
maxBaseLots: new BN(10),
540540
maxQuoteLotsIncludingFees: new BN(12000),
541541
clientOrderId: new BN(2),
@@ -546,7 +546,7 @@ describe("autocrat_v0", async function () {
546546
};
547547
let failSellArgs: PlaceOrderArgs = {
548548
side: Side.Ask,
549-
priceLots: new BN(800), // 0.8 USDC for 1 META
549+
priceLots: new BN(8_000), // 8 USDC for 1 META
550550
maxBaseLots: new BN(10),
551551
maxQuoteLotsIncludingFees: new BN(12000),
552552
clientOrderId: new BN(2),
@@ -657,9 +657,9 @@ describe("autocrat_v0", async function () {
657657

658658
let takeBuyArgs: PlaceOrderArgs = {
659659
side: Side.Bid,
660-
priceLots: new BN(1_300), // 1.3 USDC for 1 META
660+
priceLots: new BN(13000), // 13 USDC for 1 META
661661
maxBaseLots: new BN(1),
662-
maxQuoteLotsIncludingFees: new BN(2000),
662+
maxQuoteLotsIncludingFees: new BN(20000),
663663
clientOrderId: new BN(1),
664664
orderType: OrderType.Market,
665665
expiryTimestamp: new BN(0),
@@ -859,7 +859,7 @@ describe("autocrat_v0", async function () {
859859
assert.equal(
860860
(await getAccount(banksClient, aliceUnderlyingQuoteTokenAccount))
861861
.amount,
862-
10_000n * 1_000_000n - 110_000n
862+
10_000n * 1_000_000n - 1_100_000n
863863
);
864864
});
865865

@@ -1458,7 +1458,7 @@ async function initializeProposal(
14581458
);
14591459

14601460
await openbookTwap.methods
1461-
.createTwapMarket(new BN(1000))
1461+
.createTwapMarket(new BN(daoBefore.twapExpectedValue))
14621462
.accounts({
14631463
market: openbookPassMarket,
14641464
twapMarket: openbookTwapPassMarket,
@@ -1495,7 +1495,7 @@ async function initializeProposal(
14951495
daoTreasury
14961496
);
14971497
await openbookTwap.methods
1498-
.createTwapMarket(new BN(1000))
1498+
.createTwapMarket(new BN(daoBefore.twapExpectedValue))
14991499
.accounts({
15001500
market: openbookFailMarket,
15011501
twapMarket: openbookTwapFailMarket,

0 commit comments

Comments
 (0)