坚固存储时间戳/值数据,可轻松访问

发布于 2025-01-21 20:55:36 字数 1045 浏览 0 评论 0原文

我有一个有趣的用例,似乎无法解决。

问题:令牌每天获得X点。我想在一定时间段内冻结ERC721令牌(它们具有ID)。在此期间,他们每天得到0分。

我有以下来计算要点的问题:

uint32 public constant SECONDS_IN_DAY = 1 days;
struct UserInfo {
  uint256 itemCount;
  uint256 pendingPoints;
  uint256 lastUpdate;
}

mapping(address => UserInfo) public userInfo;


function pending(address account) public view returns (uint256) {
  uint256 pendingPoints = userInfo[account].pendingPoints + (((block.timestamp - userInfo[account].lastUpdate) / SECONDS_IN_DAY) * (userInfo[account].itemCount));
  return pendingPoints;
}

modifier updatePoints(address account) {
  userInfo[account].pendingPoints = pending(account);
  userInfo[account].lastUpdate = block.timestamp;
  _;
}

我无法弄清楚的问题:

  1. 当每个令牌冻结多长时间时,我该如何存储,以便我可以准确地确定何时减少待处理函数中的点。
  2. 以气体有效的方式执行此操作。

我考虑过添加一个映射,该映射容纳时间戳以及在userInfo struct中减少的每天的映射,但是我将无法检索此信息。

mapping(uint256 => uint256) perDayPointDeductions;

接下来我可以尝试什么?

I have an interesting use case that I can't seem to solve.

Problem: Tokens get X points per day. I want to freeze ERC721 tokens (they have IDs) for a certain period of time. During that time, they get 0 points per day.

I have the following to calculate points:

uint32 public constant SECONDS_IN_DAY = 1 days;
struct UserInfo {
  uint256 itemCount;
  uint256 pendingPoints;
  uint256 lastUpdate;
}

mapping(address => UserInfo) public userInfo;


function pending(address account) public view returns (uint256) {
  uint256 pendingPoints = userInfo[account].pendingPoints + (((block.timestamp - userInfo[account].lastUpdate) / SECONDS_IN_DAY) * (userInfo[account].itemCount));
  return pendingPoints;
}

modifier updatePoints(address account) {
  userInfo[account].pendingPoints = pending(account);
  userInfo[account].lastUpdate = block.timestamp;
  _;
}

The problem I can't figure out:

  1. How do I store when each token is freezed for how long so that I can accurately determine when to reduce points in the pending function.
  2. Do this in a gas efficient way.

I've thought about adding a mapping that holds a timestamp and the amount per day that gets reduced in UserInfo struct but then I would have no way to retrieve this information.

mapping(uint256 => uint256) perDayPointDeductions;

What can I try next?

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

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

发布评论

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

评论(2

吹泡泡o 2025-01-28 20:55:36

也许像快照或/和/和链链链接守护机这样的问题可能是解决此问题的可靠解决方案,也许您可​​以检查某些堆放机构的工作原理,因为您面临的问题与众不同

Maybe something like snapshots or/and a chainlink keeper could be a reliable solution to this problem, and maybe you could check how some staking mechanism works since the problem you are facing is similar staking

终难愈 2025-01-28 20:55:36

我不确定我是否很好地理解了这个问题,但是在这种情况下,我会存储数据外链,例如工具 https:/ /thegraph.com/en/

我将在函数中发出事件,这些函数只能将我的数据存储在图上。然后,我可以阅读此数据,并确定令牌会发生什么以及它们何时被冷冻。 (燃气效率),

但是如果您需要在合同中直接执行此操作(因此避免了截骨)。我会去 https://docs.chain.link.link/chain.link/chainlink-chainlink-cepers/chainlink-keepers/chainlink-keepers /介绍/

I'm not sure if I understand the issue well, but in this case I would store the data offchain e.g. tools https://thegraph.com/en/

Where I would emit events in functions that would just store my data on TheGraph. From there I can then read this data and determine what happens to the tokens and when they will be frozen. (Gas Efficient)

But if you need to do this directly in the contract ( hence avoiding the offchain). I would go for https://docs.chain.link/docs/chainlink-keepers/introduction/

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