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

[Future] Slot Math #30

Open
GalloDaSballo opened this issue Jul 22, 2022 · 0 comments
Open

[Future] Slot Math #30

GalloDaSballo opened this issue Jul 22, 2022 · 0 comments

Comments

@GalloDaSballo
Copy link
Owner

GalloDaSballo commented Jul 22, 2022

Generic Data

4e11 covers 10 thousand years
2^48 is sufficient

Most tokens have 18 decimals and less than a quadrillion circulating
That’s less than 2^128

I still have 70 bytes I can use and I can pack time and amount already

Compressing via uint128 (38 zeros)

We can half the slot required for rewards / shares via

Struct Amount {
 uint128 amount0;
 uint128 amount1;
}

shares[epochIdMod2][vault][user] = Amount(0, 1);

Meaning each slot for shares now holds 2 balances and each epoch can be found by dividing the epoch by 2 (can be Shifted, so cheaper than division) (using remainder to tell which one of the two you need)

Assuming we do this just for rewards, over 1 year, only considering the cold slot penalty, we're saving 4k gas per claim

Screenshot 2022-07-22 at 16 45 06

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

No branches or pull requests

1 participant