Skip to content

Commit

Permalink
solana: auction pubkey -> fast vaa hash in events
Browse files Browse the repository at this point in the history
  • Loading branch information
a5-pickle committed Oct 1, 2024
1 parent 41ad78f commit 1456b39
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 41 deletions.
12 changes: 6 additions & 6 deletions solana/programs/matching-engine/src/composite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub struct CheckedCustodian<'info> {
seeds = [Custodian::SEED_PREFIX],
bump = Custodian::BUMP,
)]
pub custodian: Account<'info, Custodian>,
pub custodian: Box<Account<'info, Custodian>>,
}

impl<'info> Deref for CheckedCustodian<'info> {
Expand Down Expand Up @@ -138,7 +138,7 @@ pub struct OwnerOnlyMut<'info> {
seeds = [Custodian::SEED_PREFIX],
bump = Custodian::BUMP,
)]
pub custodian: Account<'info, Custodian>,
pub custodian: Box<Account<'info, Custodian>>,
}

#[derive(Accounts)]
Expand Down Expand Up @@ -171,7 +171,7 @@ pub struct AdminMut<'info> {
seeds = [Custodian::SEED_PREFIX],
bump = Custodian::BUMP,
)]
pub custodian: Account<'info, Custodian>,
pub custodian: Box<Account<'info, Custodian>>,
}

#[derive(Accounts)]
Expand All @@ -195,7 +195,7 @@ pub struct LocalTokenRouter<'info> {
associated_token::mint = common::USDC_MINT,
associated_token::authority = token_router_emitter,
)]
pub token_router_mint_recipient: Account<'info, token::TokenAccount>,
pub token_router_mint_recipient: Box<Account<'info, token::TokenAccount>>,
}

#[derive(Accounts)]
Expand All @@ -208,7 +208,7 @@ pub struct ExistingMutRouterEndpoint<'info> {
],
bump = endpoint.bump,
)]
pub endpoint: Account<'info, RouterEndpoint>,
pub endpoint: Box<Account<'info, RouterEndpoint>>,
}

impl<'info> Deref for ExistingMutRouterEndpoint<'info> {
Expand Down Expand Up @@ -644,7 +644,7 @@ pub struct ReserveFastFillSequence<'info> {
// This check makes sure that the auction account did not exist before this
// instruction was called.
require!(
auction.vaa_hash == [0; 32],
auction.vaa_hash == <[u8; 32]>::default(),
MatchingEngineError::AuctionExists,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct SettledTokenAccountInfo {
#[derive(Debug)]
pub struct AuctionSettled {
/// The pubkey of the auction that was settled.
pub auction: Pubkey,
pub fast_vaa_hash: [u8; 32],

/// If there was an active auction, this field will have the pubkey of the best offer token that
/// was paid back and its balance after repayment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anchor_lang::prelude::*;
#[derive(Debug)]
pub struct AuctionUpdated {
pub config_id: u32,
pub auction: Pubkey,
pub fast_vaa_hash: [u8; 32],
pub vaa: Option<Pubkey>,
pub source_chain: u16,
pub target_protocol: MessageProtocol,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use anchor_lang::prelude::*;

use crate::state::FastFillSeeds;

#[event]
pub struct FastFillRedeemed {
pub prepared_by: Pubkey,
pub fast_fill: Pubkey,
pub fast_fill: FastFillSeeds,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ use anchor_lang::prelude::*;
#[event]
pub struct FastFillSequenceReserved {
pub fast_vaa_hash: [u8; 32],
pub fast_fill_seeds: FastFillSeeds,
pub fast_fill: FastFillSeeds,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anchor_lang::prelude::*;
#[event]
#[derive(Debug)]
pub struct OrderExecuted {
pub auction: Pubkey,
pub fast_vaa_hash: [u8; 32],
pub vaa: Pubkey,
pub source_chain: u16,
pub target_protocol: MessageProtocol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ fn handle_execute_fast_order<'info>(
execute_penalty: if penalized { penalty.into() } else { None },
},
OrderExecuted {
auction: auction.key(),
fast_vaa_hash: auction.vaa_hash,
vaa: fast_vaa.key(),
source_chain: auction_info.source_chain,
target_protocol: auction.target_protocol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub fn improve_offer(ctx: Context<ImproveOffer>, offer_price: u64) -> Result<()>
// Emit event for auction participants to listen to.
emit_cpi!(crate::utils::log_emit(crate::events::AuctionUpdated {
config_id: info.config_id,
auction: auction.key(),
fast_vaa_hash: auction.vaa_hash,
vaa: Default::default(),
source_chain: info.source_chain,
target_protocol: auction.target_protocol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub fn place_initial_offer_cctp(
// Emit event for auction participants to listen to.
emit_cpi!(crate::utils::log_emit(crate::events::AuctionUpdated {
config_id: info.config_id,
auction: ctx.accounts.auction.key(),
fast_vaa_hash: ctx.accounts.auction.vaa_hash,
vaa: ctx.accounts.fast_order_path.fast_vaa.key().into(),
source_chain: info.source_chain,
target_protocol: ctx.accounts.auction.target_protocol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ fn handle_settle_auction_complete(
};

emit_cpi!(crate::events::AuctionSettled {
auction: ctx.accounts.auction.key(),
fast_vaa_hash: ctx.accounts.auction.vaa_hash,
best_offer_token: settled_best_offer_result,
base_fee_token: settled_base_fee_result,
with_execute: Default::default(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn settle_none_and_prepare_fill(accounts: SettleNoneAndPrepareFill<'_, '_>) -> R
};

let auction_settled_event = AuctionSettled {
auction: auction.key(),
fast_vaa_hash: auction.vaa_hash,
best_offer_token: Default::default(),
base_fee_token: crate::events::SettledTokenAccountInfo {
key: fee_recipient_token.key(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct CompleteFastFill<'info> {
bump = fast_fill.seeds.bump,
constraint = !fast_fill.redeemed @ MatchingEngineError::FastFillAlreadyRedeemed,
)]
fast_fill: Account<'info, FastFill>,
fast_fill: Box<Account<'info, FastFill>>,

/// Only the registered local Token Router program can call this instruction. It is allowed to
/// invoke this instruction by using its emitter (i.e. its Custodian account) as a signer. We
Expand All @@ -43,7 +43,7 @@ pub struct CompleteFastFill<'info> {
mut,
token::mint = local_custody_token.mint,
)]
token_router_custody_token: Account<'info, token::TokenAccount>,
token_router_custody_token: Box<Account<'info, token::TokenAccount>>,

#[account(
constraint = {
Expand Down Expand Up @@ -84,7 +84,7 @@ pub fn complete_fast_fill(ctx: Context<CompleteFastFill>) -> Result<()> {
// Emit event that the fast fill is redeemed. Listeners can close this account.
emit_cpi!(crate::events::FastFillRedeemed {
prepared_by: ctx.accounts.fast_fill.info.prepared_by,
fast_fill: ctx.accounts.fast_fill.key(),
fast_fill: ctx.accounts.fast_fill.seeds,
});

// Finally transfer to local token router's token account.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ fn set_reserved_sequence_data(
// easily execute local orders.
Ok(FastFillSequenceReserved {
fast_vaa_hash,
fast_fill_seeds,
fast_fill: fast_fill_seeds,
})
}
35 changes: 27 additions & 8 deletions solana/ts/src/idl/json/matching_engine.json
Original file line number Diff line number Diff line change
Expand Up @@ -3535,11 +3535,16 @@
"kind": "struct",
"fields": [
{
"name": "auction",
"name": "fast_vaa_hash",
"docs": [
"The pubkey of the auction that was settled."
],
"type": "pubkey"
"type": {
"array": [
"u8",
32
]
}
},
{
"name": "best_offer_token",
Expand Down Expand Up @@ -3640,8 +3645,13 @@
"type": "u32"
},
{
"name": "auction",
"type": "pubkey"
"name": "fast_vaa_hash",
"type": {
"array": [
"u8",
32
]
}
},
{
"name": "vaa",
Expand Down Expand Up @@ -3911,7 +3921,11 @@
},
{
"name": "fast_fill",
"type": "pubkey"
"type": {
"defined": {
"name": "FastFillSeeds"
}
}
}
]
}
Expand Down Expand Up @@ -3973,7 +3987,7 @@
}
},
{
"name": "fast_fill_seeds",
"name": "fast_fill",
"type": {
"defined": {
"name": "FastFillSeeds"
Expand Down Expand Up @@ -4115,8 +4129,13 @@
"kind": "struct",
"fields": [
{
"name": "auction",
"type": "pubkey"
"name": "fast_vaa_hash",
"type": {
"array": [
"u8",
32
]
}
},
{
"name": "vaa",
Expand Down
35 changes: 27 additions & 8 deletions solana/ts/src/idl/ts/matching_engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3541,11 +3541,16 @@ export type MatchingEngine = {
"kind": "struct",
"fields": [
{
"name": "auction",
"name": "fastVaaHash",
"docs": [
"The pubkey of the auction that was settled."
],
"type": "pubkey"
"type": {
"array": [
"u8",
32
]
}
},
{
"name": "bestOfferToken",
Expand Down Expand Up @@ -3646,8 +3651,13 @@ export type MatchingEngine = {
"type": "u32"
},
{
"name": "auction",
"type": "pubkey"
"name": "fastVaaHash",
"type": {
"array": [
"u8",
32
]
}
},
{
"name": "vaa",
Expand Down Expand Up @@ -3917,7 +3927,11 @@ export type MatchingEngine = {
},
{
"name": "fastFill",
"type": "pubkey"
"type": {
"defined": {
"name": "fastFillSeeds"
}
}
}
]
}
Expand Down Expand Up @@ -3979,7 +3993,7 @@ export type MatchingEngine = {
}
},
{
"name": "fastFillSeeds",
"name": "fastFill",
"type": {
"defined": {
"name": "fastFillSeeds"
Expand Down Expand Up @@ -4121,8 +4135,13 @@ export type MatchingEngine = {
"kind": "struct",
"fields": [
{
"name": "auction",
"type": "pubkey"
"name": "fastVaaHash",
"type": {
"array": [
"u8",
32
]
}
},
{
"name": "vaa",
Expand Down
10 changes: 5 additions & 5 deletions solana/ts/src/matchingEngine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ export type SettledTokenAccountInfo = {
};

export type AuctionSettled = {
auction: PublicKey;
fastVaaHash: Array<number>;
bestOfferToken: SettledTokenAccountInfo | null;
baseFeeToken: SettledTokenAccountInfo | null;
withExecute: MessageProtocol | null;
};

export type AuctionUpdated = {
configId: number;
auction: PublicKey;
fastVaaHash: Array<number>;
vaa: PublicKey | null;
sourceChain: number;
targetProtocol: MessageProtocol;
Expand All @@ -169,7 +169,7 @@ export type AuctionUpdated = {
};

export type OrderExecuted = {
auction: PublicKey;
fastVaaHash: Array<number>;
vaa: PublicKey;
targetProtocol: MessageProtocol;
};
Expand All @@ -190,12 +190,12 @@ export type LocalFastOrderFilled = {

export type FastFillSequenceReserved = {
fastVaaHash: Array<number>;
fastFillSeeds: FastFillSeeds;
fastFill: FastFillSeeds;
};

export type FastFillRedeemed = {
preparedBy: PublicKey;
fastFill: PublicKey;
fastFill: FastFillSeeds;
};

export type MatchingEngineEvent = {
Expand Down

0 comments on commit 1456b39

Please sign in to comment.