-
Notifications
You must be signed in to change notification settings - Fork 29
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: build merkl airdrop csv based on user pool shares #1575
base: main
Are you sure you want to change the base?
Conversation
def consolidate_shares(df): | ||
consolidated = pd.DataFrame() | ||
for block in df.columns: | ||
# calculate the percentage of the pool each user owns | ||
consolidated[block] = df[block] / df[block].sum() | ||
# weigh it by the total pool size of that block | ||
consolidated[block] *= df.sum()[block] | ||
# sum the weighted percentages per user | ||
consolidated["total"] = consolidated.sum(axis=1) | ||
# divide the weighted percentages by the sum of all weights | ||
consolidated["total"] = consolidated["total"] / df.sum().sum() | ||
return consolidated |
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.
@Xeonus or @jalbrekt85 it would be good if one of you has time to draft review this function. it is at the core of this whole feature/pr
if we agree on this piece of logic, then next step for me will be to add multi pool support
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.
Mathematically, looks correct to me.
I see 2 edge cases:
- might end up with division by zero if
df[block].sum
is 0 - accumulate of floating point precision issues for small balances but that is a general limiation of data fetching
I would rewrite it to something like this so you don't do the same block sum operation
def consolidate_shares(df):
if df.empty:
raise ValueError("Empty dataframe provided")
# Pre-calculate sums to avoid redundant computation
block_sums = df.sum()
total_sum = block_sums.sum()
if total_sum == 0:
raise ValueError("No shares found in any block")
consolidated = pd.DataFrame()
for block in df.columns:
block_sum = block_sums[block]
if block_sum == 0:
continue
# Calculate weighted ownership for this block
consolidated[block] = (df[block] / block_sum) * block_sum
# Calculate final weighted average
consolidated["total"] = consolidated.sum(axis=1) / total_sum
return consolidated
closes #1563