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: add market (auction paradigm 2) to server #298

Draft
wants to merge 81 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
7370f88
add referral fee
anihamde Oct 17, 2024
868a955
add referral fee configurability
anihamde Oct 29, 2024
405f0ad
make token interfaces generic
anihamde Oct 29, 2024
a84c1ea
address comments 1
anihamde Nov 16, 2024
da7eaab
add u128 logic
anihamde Nov 16, 2024
97d4e63
added ata validation for potentially uninitialized non-searcher tas
anihamde Nov 16, 2024
71885c9
works
anihamde Nov 18, 2024
7ae9cc4
add todos
anihamde Nov 18, 2024
58caf25
a few tests
anihamde Nov 18, 2024
7c9965c
simplify deps + change seeds
anihamde Nov 18, 2024
4fb3234
dump
anihamde Dec 17, 2024
2e1fcad
remove unneeded comment
anihamde Dec 17, 2024
eebc145
better comment
anihamde Dec 17, 2024
72bf7af
better comments
anihamde Dec 17, 2024
c3704ae
slippage from % -> bps
anihamde Dec 17, 2024
af57751
remove cargo lock from server
anihamde Dec 18, 2024
6d19f08
swap program v2
guibescos Dec 18, 2024
ab999ae
undo test changes for now
guibescos Dec 18, 2024
d2f6100
chore: cargo.lock
guibescos Dec 18, 2024
07ea3c1
chore: cargo.lock
guibescos Dec 18, 2024
afb8757
Merge branch 'main' into feat/swap-program-v2
guibescos Dec 18, 2024
2566361
remove tests for now
guibescos Dec 18, 2024
8c2d4df
go
guibescos Dec 18, 2024
3294fc0
undo this change
guibescos Dec 18, 2024
f43e817
clean
guibescos Dec 18, 2024
9f8d6d6
address comments
anihamde Dec 19, 2024
57acf6c
fix little schema thing
anihamde Dec 19, 2024
f378d85
checkpoint
guibescos Dec 20, 2024
9ab15a7
checkpoint
guibescos Dec 20, 2024
e471afe
works
guibescos Dec 20, 2024
abe79eb
works
guibescos Dec 20, 2024
d6d1112
add rust toolchain
guibescos Dec 20, 2024
6a84fbb
this file isn't needed anymore
guibescos Dec 20, 2024
94758a3
go
guibescos Dec 20, 2024
180623a
Merge branch 'fix/svm-dependencies' into feat/swap-program-v2
guibescos Dec 21, 2024
002b928
fix compilation
guibescos Dec 21, 2024
6f10bfb
fix: refactor utils, only send tokens if positive balance
guibescos Dec 21, 2024
ecfb745
fix: rename express relay fee receiver ata
guibescos Dec 21, 2024
a843182
reorder accounts
guibescos Dec 21, 2024
4b14df6
Revert "reorder accounts"
guibescos Dec 21, 2024
0463660
fix: move express_relay_metadata down
guibescos Dec 21, 2024
918db65
move trader up
guibescos Dec 21, 2024
37b3890
move trader up
guibescos Dec 21, 2024
1d62f65
cleanup context
guibescos Dec 21, 2024
49442ec
a bit cleaner
guibescos Dec 21, 2024
bb6b3be
go
guibescos Dec 21, 2024
f2d3dbd
checks are complete
guibescos Dec 21, 2024
989eb1e
rename router fee ta
guibescos Dec 21, 2024
43efb5d
go
guibescos Dec 22, 2024
7df405b
improve text
guibescos Dec 22, 2024
26f9df1
reset this file
guibescos Dec 22, 2024
dc46a57
do the renames
guibescos Dec 22, 2024
9af91d6
do the renames
guibescos Dec 22, 2024
c35e612
more renames
guibescos Dec 22, 2024
6192a68
go
guibescos Dec 22, 2024
d9b1d51
fix weird imports
guibescos Dec 22, 2024
7ca54ef
fix weird imports
guibescos Dec 22, 2024
0251b99
refactor
guibescos Dec 22, 2024
46d787c
go
guibescos Dec 22, 2024
06bd354
move imports
guibescos Dec 22, 2024
e4f0b8b
typos
guibescos Dec 22, 2024
26284ae
use relayer_fee_receiver
guibescos Dec 22, 2024
2f77b96
remove cloning
guibescos Dec 22, 2024
d8cfd25
add token program fee and mint fee
guibescos Dec 22, 2024
0d1d257
go
guibescos Dec 22, 2024
b608ecf
fix
guibescos Dec 22, 2024
60d6775
go
guibescos Dec 22, 2024
1d09129
remove cargo expand
guibescos Dec 22, 2024
4ec7ef4
update comment
guibescos Dec 22, 2024
fb02285
update fee calc
guibescos Dec 22, 2024
c400c15
box express reay config
guibescos Dec 22, 2024
c7e1b12
address comments
anihamde Jan 3, 2025
3d11331
add parsing of router fee receiver ta account for swap
anihamde Jan 3, 2025
8ae8c2c
Merge branch 'feat/swap-program-v2' into feat/adapt-market-server
anihamde Jan 3, 2025
9665910
remove slippage param + verify swap ix
anihamde Jan 3, 2025
7013187
fix one thing
anihamde Jan 3, 2025
3d9eed9
Rename per_sdk folder to tilt-scripts (#303)
danimhr Dec 26, 2024
a58e6c1
Fix typos in README.md and ExpressRelayIntegration.t.sol (#306)
Hack666r Dec 26, 2024
a6fe102
fix: sdk to not swallow errors (#302)
guibescos Dec 30, 2024
a56e2fd
typo fix simulator.rs (#307)
petryshkaCODE Jan 2, 2025
3004910
fix some linting issues
anihamde Jan 3, 2025
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
8,758 changes: 8,758 additions & 0 deletions auction-server/Cargo.lock
anihamde marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

101 changes: 58 additions & 43 deletions auction-server/api-types/src/opportunity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct OpportunityBidResult {
#[derive(Serialize, Deserialize, ToSchema, Clone, PartialEq, Debug)]
#[serde(rename_all = "lowercase")]
pub enum ProgramSvm {
Phantom,
Swap,
Limo,
}

Expand Down Expand Up @@ -206,18 +206,18 @@ pub enum OpportunityCreateProgramParamsV1Svm {
#[serde_as(as = "DisplayFromStr")]
order_address: Pubkey,
},
/// Phantom program specific parameters for the opportunity.
#[serde(rename = "phantom")]
#[schema(title = "phantom")]
Phantom {
/// Swap program specific parameters for the opportunity.
#[serde(rename = "swap")]
#[schema(title = "swap")]
Swap {
/// The user wallet address which requested the quote from the wallet.
#[schema(example = "DUcTi3rDyS5QEmZ4BNRBejtArmDCWaPYGfN44vBJXKL5", value_type = String)]
#[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,
anihamde marked this conversation as resolved.
Show resolved Hide resolved
},
}

Expand Down Expand Up @@ -311,18 +311,18 @@ pub enum OpportunityParamsV1ProgramSvm {
#[serde_as(as = "DisplayFromStr")]
order_address: Pubkey,
},
/// Phantom program specific parameters for the opportunity.
#[serde(rename = "phantom")]
#[schema(title = "phantom")]
Phantom {
/// Swap program specific parameters for the opportunity.
#[serde(rename = "swap")]
#[schema(title = "swap")]
Swap {
/// The user wallet address which requested the quote from the wallet.
#[schema(example = "DUcTi3rDyS5QEmZ4BNRBejtArmDCWaPYGfN44vBJXKL5", value_type = String)]
#[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 All @@ -334,11 +334,21 @@ pub enum OpportunityParamsV1ProgramSvm {
#[serde_as(as = "DisplayFromStr")]
router_account: Pubkey,

/// The token searcher will send.
sell_token: TokenAmountSvm,
/// Details about the tokens to be swapped. Either the input token amount or the output token amount must be specified.
#[schema(inline)]
tokens: QuoteTokens,
},
}

/// The token searcher will receive.
buy_token: TokenAmountSvm,
#[derive(Serialize, Deserialize, ToSchema, Clone, PartialEq, Debug, ToResponse)]
pub enum QuoteTokens {
InputTokenSpecified {
input_token: TokenAmountSvm,
output_token: Pubkey,
},
OutputTokenSpecified {
input_token: Pubkey,
output_token: TokenAmountSvm,
},
}

Expand Down Expand Up @@ -466,40 +476,45 @@ pub struct OpportunityBidEvm {
pub signature: Signature,
}

/// Parameters needed to create a new opportunity from the Phantom wallet.
/// Parameters needed to create a new opportunity from the swap request.
/// Auction server will extract the output token price for the auction.
#[serde_as]
#[derive(Serialize, Deserialize, ToSchema, Clone, PartialEq, Debug)]
pub struct QuoteCreatePhantomV1Svm {
pub struct QuoteCreateSwapV1Svm {
anihamde marked this conversation as resolved.
Show resolved Hide resolved
/// 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,
/// The input token amount that the user wants to swap.
#[schema(example = 100)]
pub input_token_amount: u64,
/// The maximum slippage percentage that the user is willing to accept.
#[schema(example = 0.5)]
pub maximum_slippage_percentage: f64,
pub output_token_mint: Pubkey,
/// The token amount that the user wants to swap out of/into.
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)]
pub enum QuoteTokenAmount {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use serde to rename the internal fields here (for better api). Maybe take a look at docs to see how to api structure is looking like?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can talk on this part together

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also rename this to sth else :-? Maybe like QouteType?

InputToken { amount: u64 },
OutputToken { amount: u64 },
}

#[derive(Serialize, Deserialize, ToSchema, Clone, PartialEq, Debug)]
#[serde(tag = "program")]
pub enum QuoteCreateV1Svm {
#[serde(rename = "phantom")]
#[schema(title = "phantom")]
Phantom(QuoteCreatePhantomV1Svm),
#[serde(rename = "swap")]
#[schema(title = "swap")]
Swap(QuoteCreateSwapV1Svm),
}

#[derive(Serialize, Deserialize, ToSchema, Clone, PartialEq, Debug)]
Expand All @@ -522,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 All @@ -558,7 +573,7 @@ impl OpportunityCreateSvm {
match self {
OpportunityCreateSvm::V1(params) => match &params.program_params {
OpportunityCreateProgramParamsV1Svm::Limo { .. } => ProgramSvm::Limo,
OpportunityCreateProgramParamsV1Svm::Phantom { .. } => ProgramSvm::Phantom,
OpportunityCreateProgramParamsV1Svm::Swap { .. } => ProgramSvm::Swap,
},
}
}
Expand Down
4 changes: 3 additions & 1 deletion auction-server/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,11 @@ pub async fn start_api(run_options: RunOptions, store: Arc<StoreNew>) -> Result<
api_types::opportunity::QuoteCreate,
api_types::opportunity::QuoteCreateSvm,
api_types::opportunity::QuoteCreateV1Svm,
api_types::opportunity::QuoteCreatePhantomV1Svm,
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
1 change: 1 addition & 0 deletions auction-server/src/auction/entities/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct Auction<T: ChainTrait> {
pub bids: Vec<Bid<T>>,
}

#[derive(PartialEq)]
pub enum SubmitType {
ByServer,
ByOther,
Expand Down
Loading
Loading