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

Smart contract restructure #11

Open
jmacwhyte opened this issue Oct 17, 2024 · 1 comment
Open

Smart contract restructure #11

jmacwhyte opened this issue Oct 17, 2024 · 1 comment

Comments

@jmacwhyte
Copy link
Contributor

Here is my suggested structure for the smart contract based on the aspects we discussed.

Instead of storing each lock up per supporter per initiative, we can simplify by simply storing the total amount of weight per initiative. We only need to calculate decay immediately before adding more weight. If the weight ever surpasses the threshold, it can be considered a success. Then we also store a list of each supporters' lockup amounts so we know when they can be withdrawn.

Overview of what to update in the code:

  • Add top-level variable interval which specifies the inteval length (e.g. 1 day), and helper functions to calculate how many intervals have passed since a certain point of time.

  • Convert locks to a mapping(uint256 => LockInfo) to assign one LockInfo to each initiative, and change LockInfo to only include the total current weight and the timestamp of the last time the weight was updated.

  • Any time supportInitiative is called, first update the current total weight of the initiative based on how many intervals have passed since it was last updated, then add the new weight to the total. Add the token amount, expiration of the lockup, and the initiative id to the list of lockups this supporter has submited.

  • When a supporter wants to withdraw, check their list of lockups for all entries for which either the lockup expiration has passed, or for which the associated initiative has been accepted.

Next steps:

  • Add a bool variable to record if an initative has ever passed the threshold. Then allow anyone (not just owner) to accept any initiative that has passed the threshold at some point in the past (even if decay has caused it to drop below since then)
@jmacwhyte
Copy link
Contributor Author

Update on current consideration:

For each initiative, we will record a map of supporters, and for each supporter we will store a map of their contributions (locks).

To caclulate total weight, we step through each supporter and step through each lock, pass it through the function for finding the current weight, and add that to the grand total. For V1, total weight is only calculated for display in the UI and is not referenced in any on-chain transaction (in the future, we can consider calculating this every time weight is added to see if the threshold is met -- need to test if this will be too costly)

@1a35e1 1a35e1 moved this to Backlog in Path to mainnet Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

1 participant