Skip to content

Wphan/builder codes #1805

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

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open

Wphan/builder codes #1805

wants to merge 24 commits into from

Conversation

wphan
Copy link
Member

@wphan wphan commented Aug 6, 2025

No description provided.

pub authority: Pubkey,
pub total_referrer_rewards: i64,
pub total_builder_rewards: i64,
// might need padding for the len 4 bytes
Copy link
Member

Choose a reason for hiding this comment

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

do you need padding here?


#[account(zero_copy(unsafe))]
#[derive(Eq, PartialEq, Debug, Default)]
pub struct Builder {
Copy link
Member

Choose a reason for hiding this comment

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

is it less confusing if we call this referrer instead of builder?

pub authority: Pubkey,
pub total_referrer_rewards: u64,
pub total_builder_rewards: u64,
pub padding: [u8; 18],
Copy link
Member

Choose a reason for hiding this comment

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

idt you need this padding?

/// the index of the BuilderEscrow.approved_builders list, that this order's fee will settle to. Ignored
/// if bit_flag = Referral.
pub builder_idx: u8,
pub padding0: [u8; 7],
Copy link
Member

Choose a reason for hiding this comment

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

if you order the fields from largest size to smallest size, it's guranteed to minimize padding. I think if you move builder_idx to bottom, you can get rid of this extra padding

/// Checks if the order can be merged with another order. Merged orders track cumulative fees accrued
/// and are settled together, making more efficient use of the orders list.
pub fn is_mergeable(&self, other: &BuilderOrder) -> bool {
!self.is_referral_order()
Copy link
Member

Choose a reason for hiding this comment

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

can referrer orders be merged together?


/// Returns two distinct mutable references to orders by indices in one borrow of `self`.
/// Either index may be None. If both Some, they must be distinct.
pub fn get_two_orders_mut_by_indices(
Copy link
Member

Choose a reason for hiding this comment

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

gnarly, might be good to have unit test for this just to make sure each case works

builder.authority = ctx.accounts.authority.key();
builder.total_referrer_rewards = 0;
builder.total_builder_rewards = 0;
builder.padding = [0; 18];
Copy link
Member

Choose a reason for hiding this comment

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

you dont have to set this

)]
pub builder_escrow: Box<Account<'info, BuilderEscrow>>,
/// CHECK: The auth owning this account, payer of builder/ref fees
pub authority: Signer<'info>,
Copy link
Member

Choose a reason for hiding this comment

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

idk if you need to force the authority to sign?

) -> Result<()> {
let state = &mut ctx.accounts.state;
if !state.builder_referral_enabled() {
if state.admin != ctx.accounts.payer.key() {
Copy link
Member

Choose a reason for hiding this comment

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

prob want this to be allowed to be hot wallet?

)]
pub builder: AccountLoader<'info, Builder>,
/// CHECK: The builder and/or referrer authority, beneficiary of builder/ref fees
pub authority: Signer<'info>,
Copy link
Member

Choose a reason for hiding this comment

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

idk if this need to sign

} else {
0
};
let user_fee = fee.safe_add(builder_fee)?;
Copy link
Member

Choose a reason for hiding this comment

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

this might mess with accounting we do, also dont you already add it before calling update_quote_asset_and_break_even_amount, so it'd be double counting?

Comment on lines +1690 to +1691
unsafe impl Zeroable for MarketType {}
unsafe impl Pod for MarketType {}
Copy link
Member

Choose a reason for hiding this comment

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

why do you need these?

Copy link
Member Author

Choose a reason for hiding this comment

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

Needed it for MarketType to work in zerocopy

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.

3 participants