diff --git a/auction-server/api-types/src/opportunity.rs b/auction-server/api-types/src/opportunity.rs index 1b798544..0126db01 100644 --- a/auction-server/api-types/src/opportunity.rs +++ b/auction-server/api-types/src/opportunity.rs @@ -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, }, } @@ -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)] @@ -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)] @@ -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)] diff --git a/auction-server/src/api.rs b/auction-server/src/api.rs index f3fae6f1..966c351f 100644 --- a/auction-server/src/api.rs +++ b/auction-server/src/api.rs @@ -364,6 +364,8 @@ pub async fn start_api(run_options: RunOptions, store: Arc) -> 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, diff --git a/auction-server/src/opportunity/entities/opportunity_svm.rs b/auction-server/src/opportunity/entities/opportunity_svm.rs index c2b9f305..0700cd57 100644 --- a/auction-server/src/opportunity/entities/opportunity_svm.rs +++ b/auction-server/src/opportunity/entities/opportunity_svm.rs @@ -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)] @@ -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, }, ) } @@ -204,7 +204,7 @@ impl From 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? @@ -255,8 +255,8 @@ impl TryFrom> 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, }) } }; @@ -291,10 +291,10 @@ impl From 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, }), }; diff --git a/auction-server/src/opportunity/entities/quote.rs b/auction-server/src/opportunity/entities/quote.rs index f19c49c8..d99c98f7 100644 --- a/auction-server/src/opportunity/entities/quote.rs +++ b/auction-server/src/opportunity/entities/quote.rs @@ -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)] @@ -64,7 +64,7 @@ impl From 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, } } @@ -73,12 +73,12 @@ impl From for QuoteCreate { impl From 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, })) } } diff --git a/auction-server/src/opportunity/repository/models.rs b/auction-server/src/opportunity/repository/models.rs index 5d68c8a2..f7ae5dbb 100644 --- a/auction-server/src/opportunity/repository/models.rs +++ b/auction-server/src/opportunity/repository/models.rs @@ -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)] diff --git a/auction-server/src/opportunity/service/get_quote.rs b/auction-server/src/opportunity/service/get_quote.rs index 352bfea9..51ebd593 100644 --- a/auction-server/src/opportunity/service/get_quote.rs +++ b/auction-server/src/opportunity/service/get_quote.rs @@ -90,8 +90,8 @@ impl Service { 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(), @@ -246,7 +246,7 @@ impl Service { 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, }) }