Skip to content

Commit

Permalink
Remove quote tokens field
Browse files Browse the repository at this point in the history
  • Loading branch information
m30m committed Jan 17, 2025
1 parent e2658c0 commit 2d759ad
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 26 deletions.
1 change: 0 additions & 1 deletion auction-server/api-types/src/opportunity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ pub enum OpportunityCreateProgramParamsV1Svm {
#[schema(example = "DUcTi3rDyS5QEmZ4BNRBejtArmDCWaPYGfN44vBJXKL5", value_type = String)]
#[serde_as(as = "DisplayFromStr")]
output_token_program: Pubkey,
quote_tokens: QuoteTokens,
},
}

Expand Down
27 changes: 25 additions & 2 deletions auction-server/src/auction/service/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,13 +583,36 @@ impl Service<Svm> {
)));
}
};
let opp_sell_token = opp
.core_fields
.sell_tokens
.first()
.expect("Swap opportunity sell tokens must not be empty");
let opp_buy_token = opp
.core_fields
.buy_tokens
.first()
.expect("Swap opportunity buy tokens must not be empty");
let quote_tokens = match (opp_sell_token.amount, opp_buy_token.amount) {
(0, _) => QuoteTokens::OutputTokenSpecified {
input_token: opp_sell_token.token,
output_token: opp_buy_token.clone(),
},
(_, 0) => QuoteTokens::InputTokenSpecified {
input_token: opp_sell_token.clone(),
output_token: opp_buy_token.token,
},
_ => {
panic!("Non zero amount for both sell and buy tokens in swap opportunity");
}
};
let (
bid_amount,
expected_input_token,
expected_input_amount,
expected_output_token,
expected_output_amount,
) = match opp_swap_data.quote_tokens.clone() {
) = match quote_tokens.clone() {
QuoteTokens::InputTokenSpecified {
input_token,
output_token,
Expand Down Expand Up @@ -713,7 +736,7 @@ impl Service<Svm> {
}

let permission_account = get_quote_virtual_permission_account(
&opp_swap_data.quote_tokens,
&quote_tokens,
&user_wallet,
swap_data.referral_fee_bps,
);
Expand Down
10 changes: 1 addition & 9 deletions auction-server/src/opportunity/entities/opportunity_svm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ use {
crate::{
auction::entities::BidPaymentInstructionType,
kernel::entities::PermissionKey,
opportunity::{
entities::QuoteTokens,
repository,
},
opportunity::repository,
},
::express_relay::FeeToken as ProgramFeeToken,
express_relay_api_types::opportunity as api,
Expand Down Expand Up @@ -60,7 +57,6 @@ impl PartialEq<ProgramFeeToken> for FeeToken {
pub struct OpportunitySvmProgramSwap {
pub user_wallet_address: Pubkey,
pub fee_token: FeeToken,
pub quote_tokens: QuoteTokens,
pub referral_fee_bps: u16,
// TODO*: these really should not live here. they should live in the opportunity core fields, but we don't want to introduce a breaking change. in any case, the need for the token programs is another sign that quotes should be separated from the traditional opportunity struct.
pub input_token_program: Pubkey,
Expand Down Expand Up @@ -128,7 +124,6 @@ impl Opportunity for OpportunitySvm {
repository::OpportunityMetadataSvmProgramSwap {
user_wallet_address: program.user_wallet_address,
fee_token: program.fee_token,
quote_tokens: program.quote_tokens,
referral_fee_bps: program.referral_fee_bps,
input_token_program: program.input_token_program,
output_token_program: program.output_token_program,
Expand Down Expand Up @@ -296,7 +291,6 @@ impl TryFrom<repository::Opportunity<repository::OpportunityMetadataSvm>> for Op
repository::OpportunityMetadataSvmProgram::Swap(program) => {
OpportunitySvmProgram::Swap(OpportunitySvmProgramSwap {
user_wallet_address: program.user_wallet_address,
quote_tokens: program.quote_tokens,
fee_token: program.fee_token,
referral_fee_bps: program.referral_fee_bps,
input_token_program: program.input_token_program,
Expand Down Expand Up @@ -339,15 +333,13 @@ impl From<api::OpportunityCreateSvm> for OpportunityCreateSvm {
referral_fee_bps,
input_token_program,
output_token_program,
quote_tokens,
} => OpportunitySvmProgram::Swap(OpportunitySvmProgramSwap {
user_wallet_address,
// TODO*: see comment above about this arm
fee_token: FeeToken::InputToken,
referral_fee_bps,
input_token_program,
output_token_program,
quote_tokens: quote_tokens.into(),
}),
};

Expand Down
8 changes: 0 additions & 8 deletions auction-server/src/opportunity/entities/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ use {
Deserialize,
Serialize,
},
serde_with::{
serde_as,
DisplayFromStr,
},
solana_sdk::{
pubkey::Pubkey,
transaction::VersionedTransaction,
Expand All @@ -36,17 +32,13 @@ pub struct QuoteCreate {
}


#[serde_as]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum QuoteTokens {
InputTokenSpecified {
input_token: TokenAmountSvm,
#[serde_as(as = "DisplayFromStr")]
output_token: Pubkey,
},
OutputTokenSpecified {
#[serde_as(as = "DisplayFromStr")]
input_token: Pubkey,
output_token: TokenAmountSvm,
},
Expand Down
6 changes: 1 addition & 5 deletions auction-server/src/opportunity/repository/models.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use {
crate::{
models::ChainType,
opportunity::entities::{
FeeToken,
QuoteTokens,
},
opportunity::entities::FeeToken,
},
ethers::types::{
Address,
Expand Down Expand Up @@ -67,7 +64,6 @@ pub struct OpportunityMetadataSvmProgramSwap {
#[serde_as(as = "DisplayFromStr")]
pub user_wallet_address: Pubkey,
pub fee_token: FeeToken,
pub quote_tokens: QuoteTokens,
pub referral_fee_bps: u16,
#[serde_as(as = "DisplayFromStr")]
pub input_token_program: Pubkey,
Expand Down
1 change: 0 additions & 1 deletion auction-server/src/opportunity/service/get_quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ impl Service<ChainTypeSvm> {
// TODO*: we should determine this more intelligently
fee_token: entities::FeeToken::InputToken,
referral_fee_bps: quote_create.referral_fee_bps,
quote_tokens: quote_create.tokens,
input_token_program,
output_token_program,
})
Expand Down

0 comments on commit 2d759ad

Please sign in to comment.