固定性均匀分配给许多地址(拉力方法)

发布于 2025-01-26 06:35:02 字数 299 浏览 5 评论 0原文

我想将每笔交易的费用分配给3000个地址的映射(地址=> uint)。

现在,这是一个问题,因为该功能将用尽气体,因此我听说,拉动方法应该能够将其删除,而不是推动方法。

因此,相反,将所有费用放在一个单一的UINT下,然后让每个3K地址中的每一个都提取自己的份额。

现在带来了新的问题,因为池UINT永远在增加和减少(当人们拿出份额并从交易​​中获得新的收费时),以及我如何控制一个只能拿到一次但仍然不断地&amp&amp的人。均匀分布?

在这里如何解决这些分销问题,这里将不胜感激,因为我的数学远非我拥有的最强大的资产。

I want to distribute a fee from every transaction to a mapping(address=>uint) of 3000 addresses, evenly.

Now, that is an issue because the function will run out of gas, so I've heard, that instead of a push method, a pull method should be able to pull it off.

So instead, pool all fees together under one single uint and then let each of every 3k address pull their own share.

Now that brings new issues because the pool uint is forever increasing and decreasing (when people take their share out and new incoming fees from transactions) and how can I control one who may only take their share once but still continuously & evenly distributed?

Some direction here would be greatly appreciated on how to solve those distribution issues because my math is far from the strongest asset I possess.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

反差帅 2025-02-02 06:35:02

通过为每个用户存储映射来解决它,上次他们声称自己份额的总存款是什么是从当前的总收入存款中扣除的,并根据差额从当前的总出入存款中扣除。

psuedo稳固性(不包括适当的检查&互动):

uint256 totalRevShare = onDeposit() pub payable {...+=msg.value}

//..in Withdraw Function
...
uint256 unclaimedScope = totalRevShare - LastTotalRevShare[user];
LastTotalRevShare[user] = totalRevShare;
uint256 _userUnclaimedCut = unclaimedScope / totalReceivers;
...
msg.sender.call{value:_userUnclaimedCut}("");

希望它可以帮助您从推动功能转移到功能。

Solved it by having a mapping to store for every user what was the total incoming deposits last time they claimed their share and deduct that from the current total incoming deposits and give their % cut based on the difference if any.

Psuedo Solidity (excluding proper checks & interactions):

uint256 totalRevShare = onDeposit() pub payable {...+=msg.value}

//..in Withdraw Function
...
uint256 unclaimedScope = totalRevShare - LastTotalRevShare[user];
LastTotalRevShare[user] = totalRevShare;
uint256 _userUnclaimedCut = unclaimedScope / totalReceivers;
...
msg.sender.call{value:_userUnclaimedCut}("");

Hope it helps you to move from push to pull functionality.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文