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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dafyddd
Copy link
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
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.

if !maker {
let referrer_rebate = fees::referrer_rebate(native_fee_or_rebate);
open_orders.referrer_rebates_accrued += referrer_rebate;
}
Copy link
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
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
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
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