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

Feat/dynamic-fees #18

Merged
merged 9 commits into from
Jan 21, 2025
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
16 changes: 14 additions & 2 deletions openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@
"amount",
"tokenOut",
"quoteType",
"protocol"
"protocol",
"feeBps"
],
"properties": {
"amount": {
Expand All @@ -270,6 +271,17 @@
"250000000"
]
},
"feeBps": {
"type": "integer",
"format": "int32",
"description": "Fee in basis points to be charged by the Market Maker",
"examples": [
"1",
"20"
],
"maximum": 10000,
"minimum": 0
},
"protocol": {
"$ref": "#/components/schemas/Protocol"
},
Expand Down Expand Up @@ -499,4 +511,4 @@
"description": "Webhook API for RFQ providers"
}
]
}
}
8 changes: 4 additions & 4 deletions order-engine-sdk/src/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub fn validate_fill_sanitized_message(

ensure!(data.len() >= 8, "Not enough data in fill instruction");
// Must slice off anchor's discriminator first
let (discriminator, ix_data) = data.split_at(8);
let (discriminator, mut ix_data) = data.split_at(8);
ensure!(
discriminator == order_engine::client::args::Fill::DISCRIMINATOR,
"Not a fill discriminator"
Expand All @@ -116,7 +116,7 @@ pub fn validate_fill_sanitized_message(
ensure!(input_mint == &order.input_mint, "Invalid input mint");
ensure!(output_mint == &order.output_mint, "Invalid output mint");

let fill_ix = order_engine::client::args::Fill::try_from_slice(ix_data)
let fill_ix = order_engine::client::args::Fill::deserialize(&mut ix_data)
.map_err(|e| anyhow!("Invalid fill ix data {e}"))?;

// Check the input and output amount
Expand Down Expand Up @@ -250,13 +250,13 @@ pub fn validate_similar_fill_sanitized_message(
"Duplicated fill instruction"
);
ensure!(data.len() >= 8, "Not enough data in fill instruction");
let (discriminator, ix_data) = data.split_at(8);
let (discriminator, mut ix_data) = data.split_at(8);
ensure!(
discriminator == order_engine::client::args::Fill::DISCRIMINATOR,
"Not a fill discriminator"
);

let fill_ix = order_engine::client::args::Fill::try_from_slice(ix_data)
let fill_ix = order_engine::client::args::Fill::deserialize(&mut ix_data)
.map_err(|e| anyhow!("Invalid fill ix data {e}"))?;
// We check if the taker has enough balance to fill the order first
let taker = accounts.first().context("Invalid fill ix data")?.pubkey;
Expand Down
6 changes: 5 additions & 1 deletion programs/order-engine/tests/test_fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,17 @@ impl TestEnvironment {
temporary_wsol_token_account,
..
} = self;
let data = order_engine::instruction::Fill {
let mut data = order_engine::instruction::Fill {
input_amount: *input_amount,
output_amount: *output_amount,
expire_at: i64::MAX,
}
.data();

// TODO: unused data to track fee_bps
let fee_bps: u16 = 0;
data.extend(fee_bps.to_le_bytes());

let mut instruction = Instruction {
program_id: order_engine::ID,
accounts: order_engine::accounts::Fill {
Expand Down
8 changes: 6 additions & 2 deletions webhook-api/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ use serde::{Deserialize, Serialize};
use strum::{Display, EnumString};
use utoipa::ToSchema;

#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq, ToSchema, EnumString)]
#[derive(
Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq, ToSchema, EnumString, Display,
)]
#[serde(rename_all = "camelCase")]
pub enum QuoteType {
ExactIn,
ExactOut,
}

#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq, ToSchema, EnumString)]
#[derive(
Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq, ToSchema, EnumString, Display,
)]
#[serde(rename_all = "camelCase")]
pub enum Protocol {
V1,
Expand Down
3 changes: 3 additions & 0 deletions webhook-api/src/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ pub struct QuoteRequest {
#[schema(examples("10000"))]
#[serde(skip_serializing_if = "Option::is_none")]
pub suggested_prioritization_fees: Option<u64>,
/// Fee in basis points to be charged by the Market Maker
#[schema(examples("1", "20"), maximum = 10_000)]
pub fee_bps: u16,
}

/// Order to be fulfilled by the Market Maker
Expand Down
Loading