-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add closing hxro print trade accounts
- Loading branch information
1 parent
b2fc8e2
commit 6f1cbfc
Showing
8 changed files
with
268 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
hxro-print-trade-provider/program/src/helpers/close_print_trade.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use anchor_lang::prelude::*; | ||
use dex::cpi::accounts::ClosePrintTrade; | ||
use dex::cpi::close_print_trade as close_print_trade_cpi; | ||
use rfq::state::AuthoritySide; | ||
|
||
use crate::constants::OPERATOR_SEED; | ||
use crate::CleanUpPrintTradeAccounts; | ||
|
||
pub fn close_print_trade<'info>( | ||
ctx: &Context<'_, '_, '_, 'info, CleanUpPrintTradeAccounts<'info>>, | ||
) -> Result<()> { | ||
let CleanUpPrintTradeAccounts { | ||
response, | ||
operator, | ||
dex, | ||
market_product_group, | ||
taker_trg, | ||
maker_trg, | ||
operator_trg, | ||
print_trade, | ||
creator_wallet, | ||
system_program, | ||
.. | ||
} = &ctx.accounts; | ||
|
||
let (creator_trg, counterparty_trg) = | ||
if response.print_trade_initialized_by.unwrap() == AuthoritySide::Taker { | ||
(taker_trg, maker_trg) | ||
} else { | ||
(maker_trg, taker_trg) | ||
}; | ||
|
||
let accounts = ClosePrintTrade { | ||
op: operator.to_account_info(), | ||
creator: creator_trg.to_account_info(), | ||
counterparty: counterparty_trg.to_account_info(), | ||
operator: operator_trg.to_account_info(), | ||
market_product_group: market_product_group.to_account_info(), | ||
print_trade: print_trade.to_account_info(), | ||
system_program: system_program.to_account_info(), | ||
seed: response.to_account_info(), | ||
creator_wallet: creator_wallet.to_account_info(), | ||
}; | ||
|
||
let bump: u8 = *ctx.bumps.get("operator").unwrap(); | ||
let context = CpiContext { | ||
accounts, | ||
remaining_accounts: vec![], | ||
program: dex.to_account_info(), | ||
signer_seeds: &[&[OPERATOR_SEED.as_bytes(), &[bump]]], | ||
}; | ||
|
||
close_print_trade_cpi(context)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.