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

Use same name as serum-dex #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
22 changes: 11 additions & 11 deletions programs/swap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ pub mod serum_swap {
// Not used for direct swaps.
min_exchange_rate.quote_decimals = 0;

// Optional referral account (earns a referral fee).
let referral = ctx.remaining_accounts.iter().next().map(Clone::clone);
// Optional referrer account (earns a referrer fee).
let referrer = ctx.remaining_accounts.iter().next().map(Clone::clone);

// Side determines swap direction.
let (from_token, to_token) = match side {
Expand All @@ -82,7 +82,7 @@ pub mod serum_swap {
Side::Bid => orderbook.buy(amount, None)?,
Side::Ask => orderbook.sell(amount, None)?,
};
orderbook.settle(referral)?;
orderbook.settle(referrer)?;

// Token balances after the trade.
let from_amount_after = token::accessor::amount(from_token)?;
Expand Down Expand Up @@ -133,8 +133,8 @@ pub mod serum_swap {
amount: u64,
min_exchange_rate: ExchangeRate,
) -> Result<()> {
// Optional referral account (earns a referral fee).
let referral = ctx.remaining_accounts.iter().next().map(Clone::clone);
// Optional referrer account (earns a referrer fee).
let referrer = ctx.remaining_accounts.iter().next().map(Clone::clone);

// Leg 1: Sell Token A for USD(x) (or whatever quote currency is used).
let (from_amount, sell_proceeds) = {
Expand All @@ -145,7 +145,7 @@ pub mod serum_swap {
// Execute the trade.
let orderbook = ctx.accounts.orderbook_from();
orderbook.sell(amount, None)?;
orderbook.settle(referral.clone())?;
orderbook.settle(referrer.clone())?;

// Token balances after the trade.
let base_after = token::accessor::amount(&ctx.accounts.from.coin_wallet)?;
Expand All @@ -167,7 +167,7 @@ pub mod serum_swap {
// Execute the trade.
let orderbook = ctx.accounts.orderbook_to();
orderbook.buy(sell_proceeds, None)?;
orderbook.settle(referral)?;
orderbook.settle(referrer)?;

// Token balances after the trade.
let base_after = token::accessor::amount(&ctx.accounts.to.coin_wallet)?;
Expand Down Expand Up @@ -502,7 +502,7 @@ impl<'info> OrderbookClient<'info> {
// * `max_native_pc_qty` - the max number of quote currency in native token
// units (includes decimals).
// * `side` - bid or ask, i.e. the type of order.
// * `referral` - referral account, earning a fee.
// * `srm_msrm_discount` - token account to calculate fee discount.
fn order_cpi(
&self,
limit_price: u64,
Expand Down Expand Up @@ -535,7 +535,7 @@ impl<'info> OrderbookClient<'info> {
)
}

fn settle(&self, referral: Option<AccountInfo<'info>>) -> ProgramResult {
fn settle(&self, referrer: Option<AccountInfo<'info>>) -> ProgramResult {
let settle_accs = dex::SettleFunds {
market: self.market.market.clone(),
open_orders: self.market.open_orders.clone(),
Expand All @@ -548,8 +548,8 @@ impl<'info> OrderbookClient<'info> {
token_program: self.token_program.clone(),
};
let mut ctx = CpiContext::new(self.dex_program.clone(), settle_accs);
if let Some(referral) = referral {
ctx = ctx.with_remaining_accounts(vec![referral]);
if let Some(referrer) = referrer {
ctx = ctx.with_remaining_accounts(vec![referrer]);
}
dex::settle_funds(ctx)
}
Expand Down