-
Notifications
You must be signed in to change notification settings - Fork 7
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
base: main
Are you sure you want to change the base?
Conversation
} | ||
|
||
#[derive(Serialize, Deserialize, ToSchema, Clone, PartialEq, Debug)] | ||
pub enum QuoteTokenAmount { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
#[serde(tag = "program", rename_all = "lowercase")] | ||
pub enum OpportunityMetadataSvmProgram { | ||
Limo(OpportunityMetadataSvmProgramLimo), | ||
Phantom(OpportunityMetadataSvmProgramWallet), | ||
Swap(OpportunityMetadataSvmProgramWallet), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make sure that there is no phantom opportunity inside the DB. Maybe add a task to backlog for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean that we don't currently have any opportunities of this sort saved in the db?
There are some errors when running cargo check which we can resolve |
@@ -135,7 +186,7 @@ impl Service<ChainTypeSvm> { | |||
// Add metrics | |||
let labels = [ | |||
("chain_id", input.quote_create.chain_id.to_string()), | |||
("wallet", "phantom".to_string()), | |||
("router", input.quote_create.router.to_string()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can also pass in the auth name from post_quote
if we prefer
output_token_amount = output_token.amount.to_le_bytes(); | ||
[ | ||
user_wallet_address.as_ref(), | ||
input_token_mint, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems weird. I think I'd rather have a 1 bytes discriminator between InputTokenSpecified and OutputTokenSpecified. Seems like the there can be some (rare) collisions between an inputTokenSpecified opportunity and an outputTokenSpecified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that's fair, i guess the main difference here is the placement of the u64
. i can add a string discriminator at the start to be explicit like "input_token_specified" or "output_token_specified", although these should be distinct already
@@ -211,7 +211,7 @@ pub async fn post_quote( | |||
State(store): State<Arc<StoreNew>>, | |||
Json(params): Json<QuoteCreate>, | |||
) -> Result<Json<Quote>, RestError> { | |||
if get_program(&auth)? != ProgramSvm::Phantom { | |||
if get_program(&auth)? != ProgramSvm::Swap { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the program here should be KaminoSwap
@@ -336,7 +349,7 @@ impl From<OpportunitySvmProgram> for api::ProgramSvm { | |||
fn from(val: OpportunitySvmProgram) -> Self { | |||
match val { | |||
OpportunitySvmProgram::Limo(_) => api::ProgramSvm::Limo, | |||
OpportunitySvmProgram::Phantom(_) => api::ProgramSvm::Phantom, | |||
OpportunitySvmProgram::Swap(_) => api::ProgramSvm::Swap, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isnt the program name KaminoMarket
or sth like this?
Maybe we can talk on this part a bit
( | ||
chain_id.clone(), | ||
Self { | ||
wallet_program_router_account: config.wallet_program_router_account, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we receive a new opportunity for swap
, we need to check if the router is equal to wallet_program_router_account
. If we don't check it, we may have some opps for swap with a different router key, then someone can submit a submit_bid
instruction for this router and someone can submit a swap
. Then we have two different bid type for a single permission_key
which will lead to errors.
To resolve this issue, for now we should only accept the swap opps which the wallet_program_router_account
is equal to the router.
This PR adapts the server code to welcome market orders/swaps that are in Auction Paradigm 2 (bidding in one of the tokens swapped, rather than in native token).
This PR does so in the minimal way--there are some outstanding changes that will improve the code quality later on in future PRs. Some of these are:
wallet_program_router_account
, use a different way to check the bid belongs to Auction Paradigm 2. i.e. use parsed instruction data, fact that AP2 will include swap ix.