Skip to content

Commit f47b5c4

Browse files
deekernoa5-pickle
andauthored
solana: adjustments to proposals (#10)
Co-authored-by: A5 Pickle <a5-pickle@users.noreply.github.com>
1 parent 3b4ac87 commit f47b5c4

File tree

6 files changed

+140
-159
lines changed

6 files changed

+140
-159
lines changed

solana/programs/matching-engine/src/processor/admin/propose/mod.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::state::{Custodian, Proposal, ProposalAction};
55
use anchor_lang::prelude::*;
66

77
struct Propose<'ctx, 'info> {
8-
custodian: &'ctx mut Account<'info, Custodian>,
8+
custodian: &'ctx Account<'info, Custodian>,
99
proposal: &'ctx mut Account<'info, Proposal>,
1010
by: &'ctx AccountInfo<'info>,
1111
epoch_schedule: &'ctx Sysvar<'info, EpochSchedule>,
@@ -19,7 +19,7 @@ fn propose(accounts: Propose, action: ProposalAction, proposal_bump_seed: u8) ->
1919
epoch_schedule,
2020
} = accounts;
2121

22-
let slot_proposed_at = Clock::get().map(|clock| clock.slot)?;
22+
let slot_proposed_at = Clock::get().unwrap().slot;
2323

2424
cfg_if::cfg_if! {
2525
if #[cfg(feature = "integration-test")] {
@@ -43,9 +43,6 @@ fn propose(accounts: Propose, action: ProposalAction, proposal_bump_seed: u8) ->
4343
slot_enacted_at: None,
4444
});
4545

46-
// Uptick the next proposal ID.
47-
custodian.next_proposal_id += 1;
48-
4946
// Done.
5047
Ok(())
5148
}

solana/programs/matching-engine/src/processor/admin/update/auction_parameters.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
use crate::{
22
error::MatchingEngineError,
3-
state::{AuctionConfig, Custodian, Proposal, ProposalAction},
3+
state::custodian::*,
4+
state::{AuctionConfig, Proposal, ProposalAction},
45
};
56
use anchor_lang::prelude::*;
67

78
#[derive(Accounts)]
89
pub struct UpdateAuctionParameters<'info> {
910
#[account(mut)]
10-
owner: Signer<'info>,
11+
payer: Signer<'info>,
1112

12-
#[account(
13-
mut,
14-
seeds = [Custodian::SEED_PREFIX],
15-
bump = Custodian::BUMP,
16-
has_one = owner @ MatchingEngineError::OwnerOnly,
17-
)]
18-
custodian: Account<'info, Custodian>,
13+
admin: OwnerMutCustodian<'info>,
1914

2015
#[account(
2116
mut,
@@ -24,23 +19,25 @@ pub struct UpdateAuctionParameters<'info> {
2419
proposal.id.to_be_bytes().as_ref(),
2520
],
2621
bump = proposal.bump,
27-
has_one = owner,
2822
constraint = {
23+
require_keys_eq!(
24+
proposal.owner, admin.owner.key()
25+
);
2926
require!(
3027
proposal.slot_enacted_at.is_none(),
3128
MatchingEngineError::ProposalAlreadyEnacted
3229
);
3330
3431
require!(
35-
Clock::get()?.slot >= proposal.slot_enact_delay,
32+
Clock::get().unwrap().slot >= proposal.slot_enact_delay,
3633
MatchingEngineError::ProposalDelayNotExpired
3734
);
3835
3936
match &proposal.action {
4037
ProposalAction::UpdateAuctionParameters { id, .. } => {
4138
require_eq!(
4239
*id,
43-
custodian.auction_config_id + 1,
40+
admin.custodian.auction_config_id + 1,
4441
MatchingEngineError::AuctionConfigMismatch
4542
);
4643
},
@@ -54,11 +51,11 @@ pub struct UpdateAuctionParameters<'info> {
5451

5552
#[account(
5653
init,
57-
payer = owner,
54+
payer = payer,
5855
space = 8 + AuctionConfig::INIT_SPACE,
5956
seeds = [
6057
AuctionConfig::SEED_PREFIX,
61-
(custodian.auction_config_id + 1).to_be_bytes().as_ref()
58+
(admin.custodian.auction_config_id + 1).to_be_bytes().as_ref()
6259
],
6360
bump,
6461
)]
@@ -78,10 +75,13 @@ pub fn update_auction_parameters(ctx: Context<UpdateAuctionParameters>) -> Resul
7875
}
7976

8077
// Update the auction config ID.
81-
ctx.accounts.custodian.auction_config_id += 1;
78+
ctx.accounts.admin.custodian.auction_config_id += 1;
8279

8380
// Set the slot enacted at so it cannot be replayed.
84-
ctx.accounts.proposal.slot_enacted_at = Some(Clock::get().map(|clock| clock.slot)?);
81+
ctx.accounts.proposal.slot_enacted_at = Some(Clock::get().unwrap().slot);
82+
83+
// Uptick the proposal ID so that someone can create a new proposal again.
84+
ctx.accounts.admin.custodian.next_proposal_id += 1;
8585

8686
// Done.
8787
Ok(())

solana/target/idl/matching_engine.json

+14-4
Original file line numberDiff line numberDiff line change
@@ -1410,14 +1410,24 @@
14101410
"name": "updateAuctionParameters",
14111411
"accounts": [
14121412
{
1413-
"name": "owner",
1413+
"name": "payer",
14141414
"isMut": true,
14151415
"isSigner": true
14161416
},
14171417
{
1418-
"name": "custodian",
1419-
"isMut": true,
1420-
"isSigner": false
1418+
"name": "admin",
1419+
"accounts": [
1420+
{
1421+
"name": "owner",
1422+
"isMut": false,
1423+
"isSigner": true
1424+
},
1425+
{
1426+
"name": "custodian",
1427+
"isMut": true,
1428+
"isSigner": false
1429+
}
1430+
]
14211431
},
14221432
{
14231433
"name": "proposal",

solana/target/types/matching_engine.ts

+28-8
Original file line numberDiff line numberDiff line change
@@ -1410,14 +1410,24 @@ export type MatchingEngine = {
14101410
"name": "updateAuctionParameters",
14111411
"accounts": [
14121412
{
1413-
"name": "owner",
1413+
"name": "payer",
14141414
"isMut": true,
14151415
"isSigner": true
14161416
},
14171417
{
1418-
"name": "custodian",
1419-
"isMut": true,
1420-
"isSigner": false
1418+
"name": "admin",
1419+
"accounts": [
1420+
{
1421+
"name": "owner",
1422+
"isMut": false,
1423+
"isSigner": true
1424+
},
1425+
{
1426+
"name": "custodian",
1427+
"isMut": true,
1428+
"isSigner": false
1429+
}
1430+
]
14211431
},
14221432
{
14231433
"name": "proposal",
@@ -4191,14 +4201,24 @@ export const IDL: MatchingEngine = {
41914201
"name": "updateAuctionParameters",
41924202
"accounts": [
41934203
{
4194-
"name": "owner",
4204+
"name": "payer",
41954205
"isMut": true,
41964206
"isSigner": true
41974207
},
41984208
{
4199-
"name": "custodian",
4200-
"isMut": true,
4201-
"isSigner": false
4209+
"name": "admin",
4210+
"accounts": [
4211+
{
4212+
"name": "owner",
4213+
"isMut": false,
4214+
"isSigner": true
4215+
},
4216+
{
4217+
"name": "custodian",
4218+
"isMut": true,
4219+
"isSigner": false
4220+
}
4221+
]
42024222
},
42034223
{
42044224
"name": "proposal",

solana/ts/src/matchingEngine/index.ts

+26-2
Original file line numberDiff line numberDiff line change
@@ -500,14 +500,35 @@ export class MatchingEngineProgram {
500500
.instruction();
501501
}
502502

503+
async closeProposalIx(accounts: { owner: PublicKey }): Promise<TransactionInstruction> {
504+
const { owner } = accounts;
505+
506+
const proposal = await this.proposalAddress();
507+
const { by: proposedBy } = await this.fetchProposal({ address: proposal });
508+
509+
return this.program.methods
510+
.closeProposal()
511+
.accounts({
512+
admin: {
513+
owner,
514+
custodian: this.custodianAddress(),
515+
},
516+
proposedBy,
517+
proposal,
518+
})
519+
.instruction();
520+
}
521+
503522
async updateAuctionParametersIx(accounts: {
504523
owner: PublicKey;
524+
payer?: PublicKey;
505525
custodian?: PublicKey;
506526
proposal?: PublicKey;
507527
auctionConfig?: PublicKey;
508528
}): Promise<TransactionInstruction> {
509529
const {
510530
owner,
531+
payer: inputPayer,
511532
custodian: inputCustodian,
512533
proposal: inputProposal,
513534
auctionConfig: inputAuctionConfig,
@@ -526,8 +547,11 @@ export class MatchingEngineProgram {
526547
return this.program.methods
527548
.updateAuctionParameters()
528549
.accounts({
529-
owner,
530-
custodian: inputCustodian ?? this.custodianAddress(),
550+
payer: inputPayer ?? owner,
551+
admin: {
552+
owner,
553+
custodian: inputCustodian ?? this.custodianAddress(),
554+
},
531555
proposal: inputProposal ?? (await this.proposalAddress()),
532556
auctionConfig,
533557
})

0 commit comments

Comments
 (0)