Skip to content

Commit

Permalink
slippage from % -> bps
Browse files Browse the repository at this point in the history
  • Loading branch information
anihamde committed Dec 17, 2024
1 parent 72bf7af commit c3704ae
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 53 deletions.
44 changes: 22 additions & 22 deletions auction-server/api-types/src/opportunity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ pub enum OpportunityCreateProgramParamsV1Svm {
#[serde_as(as = "DisplayFromStr")]
user_wallet_address: Pubkey,

/// The maximum slippage percentage that the user is willing to accept.
#[schema(example = 0.5, value_type = f64)]
maximum_slippage_percentage: f64,
/// The maximum slippage in basis points that the user is willing to accept.
#[schema(example = 50, value_type = u16)]
maximum_slippage_bps: u16,
},
}

Expand Down Expand Up @@ -320,9 +320,9 @@ pub enum OpportunityParamsV1ProgramSvm {
#[serde_as(as = "DisplayFromStr")]
user_wallet_address: Pubkey,

/// The maximum slippage percentage that the user is willing to accept.
#[schema(example = 0.5, value_type = f64)]
maximum_slippage_percentage: f64,
/// The maximum slippage in basis points that the user is willing to accept.
#[schema(example = 50, value_type = u16)]
maximum_slippage_bps: u16,

/// The permission account to be permitted by the ER contract for the opportunity execution of the protocol.
#[schema(example = "DUcTi3rDyS5QEmZ4BNRBejtArmDCWaPYGfN44vBJXKL5", value_type = String)]
Expand Down Expand Up @@ -484,23 +484,23 @@ pub struct QuoteCreateSwapV1Svm {
/// The user wallet address which requested the quote from the wallet.
#[schema(example = "DUcTi3rDyS5QEmZ4BNRBejtArmDCWaPYGfN44vBJXKL5", value_type = String)]
#[serde_as(as = "DisplayFromStr")]
pub user_wallet_address: Pubkey,
pub user_wallet_address: Pubkey,
/// The token mint address of the input token.
#[schema(example = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", value_type = String)]
#[serde_as(as = "DisplayFromStr")]
pub input_token_mint: Pubkey,
pub input_token_mint: Pubkey,
/// The token mint address of the output token.
#[schema(example = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", value_type = String)]
#[serde_as(as = "DisplayFromStr")]
pub output_token_mint: Pubkey,
pub output_token_mint: Pubkey,
/// The token amount that the user wants to swap out of/into.
pub token_amount: QuoteTokenAmount,
/// The maximum slippage percentage that the user is willing to accept.
#[schema(example = 0.5)]
pub maximum_slippage_percentage: f64,
pub token_amount: QuoteTokenAmount,
/// The maximum slippage in basis points that the user is willing to accept.
#[schema(example = 50)]
pub maximum_slippage_bps: u16,
/// The chain id for creating the quote.
#[schema(example = "solana", value_type = String)]
pub chain_id: ChainId,
pub chain_id: ChainId,
}

#[derive(Serialize, Deserialize, ToSchema, Clone, PartialEq, Debug)]
Expand Down Expand Up @@ -537,20 +537,20 @@ pub struct QuoteV1Svm {
/// The signed transaction for the quote to be executed on chain which is valid until the expiration time.
#[schema(example = "SGVsbG8sIFdvcmxkIQ==", value_type = String)]
#[serde(with = "crate::serde::transaction_svm")]
pub transaction: VersionedTransaction,
pub transaction: VersionedTransaction,
/// The expiration time of the quote (in seconds since the Unix epoch).
#[schema(example = 1_700_000_000_000_000i64, value_type = i64)]
pub expiration_time: i64,
pub expiration_time: i64,
/// The input token amount that the user wants to swap.
pub input_token: TokenAmountSvm,
pub input_token: TokenAmountSvm,
/// The output token amount that the user will receive.
pub output_token: TokenAmountSvm,
/// The maximum slippage percentage that the user is willing to accept.
#[schema(example = 0.5)]
pub maximum_slippage_percentage: f64,
pub output_token: TokenAmountSvm,
/// The maximum slippage in basis points that the user is willing to accept.
#[schema(example = 50)]
pub maximum_slippage_bps: u16,
/// The chain id for the quote.
#[schema(example = "solana", value_type = String)]
pub chain_id: ChainId,
pub chain_id: ChainId,
}

#[derive(Serialize, Deserialize, ToSchema, Clone, PartialEq, Debug)]
Expand Down
2 changes: 2 additions & 0 deletions auction-server/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ pub async fn start_api(run_options: RunOptions, store: Arc<StoreNew>) -> Result<
api_types::opportunity::QuoteCreateSwapV1Svm,
api_types::opportunity::Quote,
api_types::opportunity::QuoteSvm,
api_types::opportunity::QuoteTokenAmount,
api_types::opportunity::QuoteTokens,
api_types::opportunity::QuoteV1Svm,
api_types::opportunity::OpportunityDelete,
api_types::opportunity::OpportunityDeleteSvm,
Expand Down
18 changes: 9 additions & 9 deletions auction-server/src/opportunity/entities/opportunity_svm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ pub struct OpportunitySvmProgramLimo {

#[derive(Debug, Clone, PartialEq)]
pub struct OpportunitySvmProgramWallet {
pub user_wallet_address: Pubkey,
pub maximum_slippage_percentage: f64,
pub user_wallet_address: Pubkey,
pub maximum_slippage_bps: u16,
}

#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -96,8 +96,8 @@ impl Opportunity for OpportunitySvm {
OpportunitySvmProgram::Swap(program) => {
repository::OpportunityMetadataSvmProgram::Swap(
repository::OpportunityMetadataSvmProgramWallet {
user_wallet_address: program.user_wallet_address,
maximum_slippage_percentage: program.maximum_slippage_percentage,
user_wallet_address: program.user_wallet_address,
maximum_slippage_bps: program.maximum_slippage_bps,
},
)
}
Expand Down Expand Up @@ -204,7 +204,7 @@ impl From<OpportunitySvm> for api::OpportunitySvm {
};
api::OpportunityParamsV1ProgramSvm::Swap {
user_wallet_address: program.user_wallet_address,
maximum_slippage_percentage: program.maximum_slippage_percentage,
maximum_slippage_bps: program.maximum_slippage_bps,
permission_account: val.permission_account,
router_account: val.router,
// TODO can we make it type safe?
Expand Down Expand Up @@ -255,8 +255,8 @@ impl TryFrom<repository::Opportunity<repository::OpportunityMetadataSvm>> for Op
}
repository::OpportunityMetadataSvmProgram::Swap(program) => {
OpportunitySvmProgram::Swap(OpportunitySvmProgramWallet {
user_wallet_address: program.user_wallet_address,
maximum_slippage_percentage: program.maximum_slippage_percentage,
user_wallet_address: program.user_wallet_address,
maximum_slippage_bps: program.maximum_slippage_bps,
})
}
};
Expand Down Expand Up @@ -291,10 +291,10 @@ impl From<api::OpportunityCreateSvm> for OpportunityCreateSvm {
}),
api::OpportunityCreateProgramParamsV1Svm::Swap {
user_wallet_address,
maximum_slippage_percentage,
maximum_slippage_bps,
} => OpportunitySvmProgram::Swap(OpportunitySvmProgramWallet {
user_wallet_address,
maximum_slippage_percentage,
maximum_slippage_bps,
}),
};

Expand Down
34 changes: 17 additions & 17 deletions auction-server/src/opportunity/entities/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ use {

#[derive(Debug, Clone, PartialEq)]
pub struct Quote {
pub transaction: VersionedTransaction,
pub transaction: VersionedTransaction,
// The expiration time of the quote (in seconds since the Unix epoch)
pub expiration_time: i64,
pub input_token: TokenAmountSvm,
pub output_token: TokenAmountSvm,
pub maximum_slippage_percentage: f64,
pub chain_id: ChainId,
pub expiration_time: i64,
pub input_token: TokenAmountSvm,
pub output_token: TokenAmountSvm,
pub maximum_slippage_bps: u16,
pub chain_id: ChainId,
}

#[derive(Debug, Clone, PartialEq)]
pub struct QuoteCreate {
pub user_wallet_address: Pubkey,
pub tokens: QuoteTokens,
pub maximum_slippage_percentage: f64,
pub chain_id: ChainId,
pub user_wallet_address: Pubkey,
pub tokens: QuoteTokens,
pub maximum_slippage_bps: u16,
pub chain_id: ChainId,
}

#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -64,7 +64,7 @@ impl From<api::QuoteCreate> for QuoteCreate {
Self {
user_wallet_address: params.user_wallet_address,
tokens,
maximum_slippage_percentage: params.maximum_slippage_percentage,
maximum_slippage_bps: params.maximum_slippage_bps,
chain_id: params.chain_id,
}
}
Expand All @@ -73,12 +73,12 @@ impl From<api::QuoteCreate> for QuoteCreate {
impl From<Quote> for api::Quote {
fn from(quote: Quote) -> Self {
api::Quote::Svm(api::QuoteSvm::V1(api::QuoteV1Svm {
transaction: quote.transaction,
expiration_time: quote.expiration_time,
input_token: quote.input_token.into(),
output_token: quote.output_token.into(),
maximum_slippage_percentage: quote.maximum_slippage_percentage,
chain_id: quote.chain_id,
transaction: quote.transaction,
expiration_time: quote.expiration_time,
input_token: quote.input_token.into(),
output_token: quote.output_token.into(),
maximum_slippage_bps: quote.maximum_slippage_bps,
chain_id: quote.chain_id,
}))
}
}
4 changes: 2 additions & 2 deletions auction-server/src/opportunity/repository/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ pub struct OpportunityMetadataSvmProgramLimo {
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct OpportunityMetadataSvmProgramWallet {
#[serde_as(as = "DisplayFromStr")]
pub user_wallet_address: Pubkey,
pub maximum_slippage_percentage: f64,
pub user_wallet_address: Pubkey,
pub maximum_slippage_bps: u16,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
Expand Down
6 changes: 3 additions & 3 deletions auction-server/src/opportunity/service/get_quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ impl Service<ChainTypeSvm> {
router,
permission_account,
program: entities::OpportunitySvmProgram::Swap(entities::OpportunitySvmProgramWallet {
user_wallet_address: quote_create.user_wallet_address,
maximum_slippage_percentage: quote_create.maximum_slippage_percentage,
user_wallet_address: quote_create.user_wallet_address,
maximum_slippage_bps: quote_create.maximum_slippage_bps,
}),
// TODO extract latest slot
slot: Slot::default(),
Expand Down Expand Up @@ -246,7 +246,7 @@ impl Service<ChainTypeSvm> {
expiration_time: deadline,
input_token,
output_token,
maximum_slippage_percentage: input.quote_create.maximum_slippage_percentage,
maximum_slippage_bps: input.quote_create.maximum_slippage_bps,
chain_id: input.quote_create.chain_id,
})
}
Expand Down

0 comments on commit c3704ae

Please sign in to comment.