Skip to content

optimize settle_funds and accrue fee rebate at time of trade instead of event queue#149

Open
dafyddd wants to merge 1 commit intoproject-serum:masterfrom
dafyddd:master
Open

optimize settle_funds and accrue fee rebate at time of trade instead of event queue#149
dafyddd wants to merge 1 commit intoproject-serum:masterfrom
dafyddd:master

Conversation

@dafyddd
Copy link
Copy Markdown
Contributor

@dafyddd dafyddd commented Jul 13, 2021

It saves something like 20k compute on settle funds by avoiding the extra CPI call. This has been working well on devnet for a month.

…ferrer_pc_wallet; Giving open_orders rebate at the time of trade instead of at time of event queue processing
Copy link
Copy Markdown
Contributor

@armaniferrante armaniferrante left a comment

Choose a reason for hiding this comment

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

Will leave open to give @sconybeare a chance to take a look next week. But these changes all look good to me.

Comment thread dex/src/state.rs
if !maker {
let referrer_rebate = fees::referrer_rebate(native_fee_or_rebate);
open_orders.referrer_rebates_accrued += referrer_rebate;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think that if this is deployed in a program upgrade, any rebates sitting in the event queues will be lost.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, you're right. So the total loss would be the 20% of the fee value of all trades that are on the event queue at the time this deployment goes out. My instinct is that it's a small loss because cranks usually clear out the event queue very quickly and most queues don't have trades on them, but I don't actually know the stats on this.

It simplifies the settling process for us by a lot. With the referrer rebate being granted at time of trade, we can put a SettleFunds instruction right after a NewOrder instruction and not have to wait to send a settle funds. We try to hide the settling thing as much as possible from users 😄

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My guesstimate is that both the UX improvement and the 20k compute units saved are worth more than the 20% of the fee value of all trades at time of the deployment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

20k compute units 😮 ? Spl token transfer CPI usually is ~3k units.
But even 3k units saving is good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants