Remove Instruction wrapper structs and name functions after enum fields
This commit is contained in:
@@ -59,89 +59,88 @@ pub enum ExchangeInstruction {
|
||||
/// key 6 - Token account in which to deposit the brokers profit from the swap.
|
||||
SwapRequest,
|
||||
}
|
||||
impl ExchangeInstruction {
|
||||
pub fn new_account_request(owner: &Pubkey, new: &Pubkey) -> Instruction {
|
||||
let account_metas = vec![
|
||||
AccountMeta::new(*owner, true),
|
||||
AccountMeta::new(*new, false),
|
||||
];
|
||||
Instruction::new(id(), &ExchangeInstruction::AccountRequest, account_metas)
|
||||
}
|
||||
|
||||
pub fn new_transfer_request(
|
||||
owner: &Pubkey,
|
||||
to: &Pubkey,
|
||||
from: &Pubkey,
|
||||
token: Token,
|
||||
tokens: u64,
|
||||
) -> Instruction {
|
||||
let account_metas = vec![
|
||||
AccountMeta::new(*owner, true),
|
||||
AccountMeta::new(*to, false),
|
||||
AccountMeta::new(*from, false),
|
||||
];
|
||||
Instruction::new(
|
||||
id(),
|
||||
&ExchangeInstruction::TransferRequest(token, tokens),
|
||||
account_metas,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn new_trade_request(
|
||||
owner: &Pubkey,
|
||||
trade: &Pubkey,
|
||||
direction: Direction,
|
||||
pair: TokenPair,
|
||||
tokens: u64,
|
||||
price: u64,
|
||||
src_account: &Pubkey,
|
||||
dst_account: &Pubkey,
|
||||
) -> Instruction {
|
||||
let account_metas = vec![
|
||||
AccountMeta::new(*owner, true),
|
||||
AccountMeta::new(*trade, false),
|
||||
AccountMeta::new(*src_account, false),
|
||||
];
|
||||
Instruction::new(
|
||||
id(),
|
||||
&ExchangeInstruction::TradeRequest(TradeRequestInfo {
|
||||
direction,
|
||||
pair,
|
||||
tokens,
|
||||
price,
|
||||
dst_account: *dst_account,
|
||||
}),
|
||||
account_metas,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn new_trade_cancellation(owner: &Pubkey, trade: &Pubkey, account: &Pubkey) -> Instruction {
|
||||
let account_metas = vec![
|
||||
AccountMeta::new(*owner, true),
|
||||
AccountMeta::new(*trade, false),
|
||||
AccountMeta::new(*account, false),
|
||||
];
|
||||
Instruction::new(id(), &ExchangeInstruction::TradeCancellation, account_metas)
|
||||
}
|
||||
|
||||
pub fn new_swap_request(
|
||||
owner: &Pubkey,
|
||||
swap: &Pubkey,
|
||||
to_trade: &Pubkey,
|
||||
from_trade: &Pubkey,
|
||||
to_trade_account: &Pubkey,
|
||||
from_trade_account: &Pubkey,
|
||||
profit_account: &Pubkey,
|
||||
) -> Instruction {
|
||||
let account_metas = vec![
|
||||
AccountMeta::new(*owner, true),
|
||||
AccountMeta::new(*swap, false),
|
||||
AccountMeta::new(*to_trade, false),
|
||||
AccountMeta::new(*from_trade, false),
|
||||
AccountMeta::new(*to_trade_account, false),
|
||||
AccountMeta::new(*from_trade_account, false),
|
||||
AccountMeta::new(*profit_account, false),
|
||||
];
|
||||
Instruction::new(id(), &ExchangeInstruction::SwapRequest, account_metas)
|
||||
}
|
||||
pub fn account_request(owner: &Pubkey, new: &Pubkey) -> Instruction {
|
||||
let account_metas = vec![
|
||||
AccountMeta::new(*owner, true),
|
||||
AccountMeta::new(*new, false),
|
||||
];
|
||||
Instruction::new(id(), &ExchangeInstruction::AccountRequest, account_metas)
|
||||
}
|
||||
|
||||
pub fn transfer_request(
|
||||
owner: &Pubkey,
|
||||
to: &Pubkey,
|
||||
from: &Pubkey,
|
||||
token: Token,
|
||||
tokens: u64,
|
||||
) -> Instruction {
|
||||
let account_metas = vec![
|
||||
AccountMeta::new(*owner, true),
|
||||
AccountMeta::new(*to, false),
|
||||
AccountMeta::new(*from, false),
|
||||
];
|
||||
Instruction::new(
|
||||
id(),
|
||||
&ExchangeInstruction::TransferRequest(token, tokens),
|
||||
account_metas,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn trade_request(
|
||||
owner: &Pubkey,
|
||||
trade: &Pubkey,
|
||||
direction: Direction,
|
||||
pair: TokenPair,
|
||||
tokens: u64,
|
||||
price: u64,
|
||||
src_account: &Pubkey,
|
||||
dst_account: &Pubkey,
|
||||
) -> Instruction {
|
||||
let account_metas = vec![
|
||||
AccountMeta::new(*owner, true),
|
||||
AccountMeta::new(*trade, false),
|
||||
AccountMeta::new(*src_account, false),
|
||||
];
|
||||
Instruction::new(
|
||||
id(),
|
||||
&ExchangeInstruction::TradeRequest(TradeRequestInfo {
|
||||
direction,
|
||||
pair,
|
||||
tokens,
|
||||
price,
|
||||
dst_account: *dst_account,
|
||||
}),
|
||||
account_metas,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn trade_cancellation(owner: &Pubkey, trade: &Pubkey, account: &Pubkey) -> Instruction {
|
||||
let account_metas = vec![
|
||||
AccountMeta::new(*owner, true),
|
||||
AccountMeta::new(*trade, false),
|
||||
AccountMeta::new(*account, false),
|
||||
];
|
||||
Instruction::new(id(), &ExchangeInstruction::TradeCancellation, account_metas)
|
||||
}
|
||||
|
||||
pub fn swap_request(
|
||||
owner: &Pubkey,
|
||||
swap: &Pubkey,
|
||||
to_trade: &Pubkey,
|
||||
from_trade: &Pubkey,
|
||||
to_trade_account: &Pubkey,
|
||||
from_trade_account: &Pubkey,
|
||||
profit_account: &Pubkey,
|
||||
) -> Instruction {
|
||||
let account_metas = vec![
|
||||
AccountMeta::new(*owner, true),
|
||||
AccountMeta::new(*swap, false),
|
||||
AccountMeta::new(*to_trade, false),
|
||||
AccountMeta::new(*from_trade, false),
|
||||
AccountMeta::new(*to_trade_account, false),
|
||||
AccountMeta::new(*from_trade_account, false),
|
||||
AccountMeta::new(*profit_account, false),
|
||||
];
|
||||
Instruction::new(id(), &ExchangeInstruction::SwapRequest, account_metas)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user