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

solana: add proposal events #74

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions solana/programs/matching-engine/src/events/enacted.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use crate::state::ProposalAction;
use anchor_lang::prelude::*;

#[event]
pub struct Enacted {
pub action: ProposalAction,
}
6 changes: 6 additions & 0 deletions solana/programs/matching-engine/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@ pub use auction_settled::*;
mod auction_updated;
pub use auction_updated::*;

mod enacted;
pub use enacted::*;

mod order_executed;
pub use order_executed::*;

mod proposed;
pub use proposed::*;
7 changes: 7 additions & 0 deletions solana/programs/matching-engine/src/events/proposed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use crate::state::ProposalAction;
use anchor_lang::prelude::*;

#[event]
pub struct Proposed {
pub action: ProposalAction,
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,22 @@ pub fn propose_auction_parameters(
crate::utils::auction::require_valid_parameters(&parameters)?;

let id = ctx.accounts.admin.custodian.auction_config_id + 1;
let action = ProposalAction::UpdateAuctionParameters { id, parameters };

super::propose(
super::Propose {
custodian: &ctx.accounts.admin.custodian,
proposal: &mut ctx.accounts.proposal,
by: &ctx.accounts.admin.owner_or_assistant,
epoch_schedule: &ctx.accounts.epoch_schedule,
},
ProposalAction::UpdateAuctionParameters { id, parameters },
action,
ctx.bumps.proposal,
)
)?;

// Emit event reflecting the proposal.
emit!(crate::events::Proposed { action });

// Done.
Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ pub struct UpdateAuctionParameters<'info> {
}

pub fn update_auction_parameters(ctx: Context<UpdateAuctionParameters>) -> Result<()> {
if let ProposalAction::UpdateAuctionParameters { id, parameters } = ctx.accounts.proposal.action
{
let action = ctx.accounts.proposal.action;

// Emit event to reflect enacting the proposal.
emit!(crate::events::Enacted { action });

if let ProposalAction::UpdateAuctionParameters { id, parameters } = action {
ctx.accounts
.auction_config
.set_inner(AuctionConfig { id, parameters });
Expand Down
2 changes: 1 addition & 1 deletion solana/programs/matching-engine/src/state/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anchor_lang::prelude::*;

use crate::AuctionParameters;

#[derive(Debug, AnchorSerialize, AnchorDeserialize, Clone, InitSpace, PartialEq, Eq)]
#[derive(Debug, AnchorSerialize, AnchorDeserialize, Clone, InitSpace, PartialEq, Eq, Copy)]
pub enum ProposalAction {
None,
UpdateAuctionParameters {
Expand Down
24 changes: 24 additions & 0 deletions solana/target/idl/matching_engine.json
Original file line number Diff line number Diff line change
Expand Up @@ -3125,6 +3125,18 @@
}
]
},
{
"name": "Enacted",
"fields": [
{
"name": "action",
"type": {
"defined": "ProposalAction"
},
"index": false
}
]
},
{
"name": "OrderExecuted",
"fields": [
Expand All @@ -3146,6 +3158,18 @@
"index": false
}
]
},
{
"name": "Proposed",
"fields": [
{
"name": "action",
"type": {
"defined": "ProposalAction"
},
"index": false
}
]
}
],
"errors": [
Expand Down
48 changes: 48 additions & 0 deletions solana/target/types/matching_engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3125,6 +3125,18 @@ export type MatchingEngine = {
}
]
},
{
"name": "Enacted",
"fields": [
{
"name": "action",
"type": {
"defined": "ProposalAction"
},
"index": false
}
]
},
{
"name": "OrderExecuted",
"fields": [
Expand All @@ -3146,6 +3158,18 @@ export type MatchingEngine = {
"index": false
}
]
},
{
"name": "Proposed",
"fields": [
{
"name": "action",
"type": {
"defined": "ProposalAction"
},
"index": false
}
]
}
],
"errors": [
Expand Down Expand Up @@ -6487,6 +6511,18 @@ export const IDL: MatchingEngine = {
}
]
},
{
"name": "Enacted",
"fields": [
{
"name": "action",
"type": {
"defined": "ProposalAction"
},
"index": false
}
]
},
{
"name": "OrderExecuted",
"fields": [
Expand All @@ -6508,6 +6544,18 @@ export const IDL: MatchingEngine = {
"index": false
}
]
},
{
"name": "Proposed",
"fields": [
{
"name": "action",
"type": {
"defined": "ProposalAction"
},
"index": false
}
]
}
],
"errors": [
Expand Down
17 changes: 17 additions & 0 deletions solana/ts/src/matchingEngine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
MessageProtocol,
PreparedOrderResponse,
Proposal,
ProposalAction,
RedeemedFastFill,
RouterEndpoint,
} from "./state";
Expand Down Expand Up @@ -155,6 +156,14 @@ export type OrderExecuted = {
targetProtocol: MessageProtocol;
};

export type Proposed = {
action: ProposalAction;
};

export type Enacted = {
action: ProposalAction;
};

export class MatchingEngineProgram {
private _programId: ProgramId;
private _mint: PublicKey;
Expand Down Expand Up @@ -189,6 +198,14 @@ export class MatchingEngineProgram {
return this.program.addEventListener("OrderExecuted", callback);
}

onProposed(callback: (event: Proposed, slot: number, signature: string) => void) {
return this.program.addEventListener("Proposed", callback);
}

onEnacted(callback: (event: Enacted, slot: number, signature: string) => void) {
return this.program.addEventListener("Enacted", callback);
}

custodianAddress(): PublicKey {
return Custodian.address(this.ID);
}
Expand Down
Loading