Skip to content

Conversation

@laruh
Copy link

@laruh laruh commented Mar 25, 2025

This PR introduces the "premium" feature for TPU.
Maker is now able to set the "premium" field in the setprice request, which represents the extra amount of rel coins they require from taker.

Additionally, this PR introduces specific order matching behavior for TPU.
When a taker request is processed by a maker order, the taker order is treated as a limit order if the taker "buys." This means taker will receive as much as they want to buy, and they will also send the entire amount they offered for the purchase.
If taker action is "sell," then taker order is treated as a market order.

It is worth mentioning that for the taker "sell" action, we allow maker to send fewer coins, instead of asking taker to send extra rel premium.

Copy link

@borngraced borngraced left a comment

Choose a reason for hiding this comment

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

Great work! minor notes

#[serde(default, skip_serializing_if = "SwapVersion::is_legacy")]
pub swap_version: SwapVersion,
#[serde(default, skip_serializing_if = "Option::is_none")]
premium: Option<MmNumber>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not add a doc comment for this field?

@dimxy
Copy link
Collaborator

dimxy commented Apr 3, 2025

As I can see, we don't show premium in the orderbook so when users are viewing orderbook they see only order prices from 'setprice' rpc and are not aware of extra premium pay. But when 'buy' or 'sell' order is created its price should take into account the premium part. How would user know this part amount?
(Should we not show premium in orderbook?)

}

let is_legacy = self.swap_version.is_legacy() || taker.swap_version.is_legacy();

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: we may get premium as reference here, like:

        let premium_default = MmNumber::default();
        let premium = self.premium.as_ref().unwrap_or(&premium_default);

and use it within match taker.action {...} instead of cloning.
(but not sure this is much better though)

OrderMatchResult::NotMatched
// taker_rel_amount must cover the premium requested by maker
let required_rel_amount =
taker_base_amount * &self.price + self.premium.clone().unwrap_or_default();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here we require Taker to pay Maker order's premium.
As I can see, premium is a fixed amount in rel coin units, assigned when the order is created.
What if the order is filled only partially, will Taker always pay the same premium amount (that is, shouldn't premium be proportional to the order amount being filled)?

Copy link
Author

Choose a reason for hiding this comment

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

What if the order is filled only partially, will Taker always pay the same premium amount

yes, premium is a fixed rel amount maker requires for a swap. They ask it for the action (swap) not for a trading volume.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is not fair:
If an order was filled 3 times partially the maker would receive 3 premiums.
If same order is filled only one time for the full amount the maker receives only 1 premium.
This seems unfair. I think the maker should receive same premium no matter how many times the order was filled.
For this the premium should be calculated proportionally to the amount filled.

(Not sure though, maybe this was discussed already and was decided to pay premium like it is implemented now)

Copy link
Author

@laruh laruh Apr 4, 2025

Choose a reason for hiding this comment

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

During swap maker pays fees for transactions, which doesn't depend on tx value, its better to treat premium as guaranteed fixed amount which could cover maker expenses on swap

Copy link

@borngraced borngraced left a comment

Choose a reason for hiding this comment

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

thanks

@dimxy
Copy link
Collaborator

dimxy commented May 2, 2025

I am okay with the code in this PR,
but I am not sure I am totally understand the whole premium concept (like how it should be calculated and paid).
So I suggest adding TODOs to the PR description: I guess, there will be more code to validate and actually pay the premium amount.

@laruh laruh removed the 2.5.0-beta label May 5, 2025
@shamardy shamardy marked this pull request as draft June 11, 2025 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants