Stateful pool contract question

Lets say I want to create a smart contract that acts as a pool of Algos. Any account can send Algos to the pool account. The catch is that there is an expiration date to the pool, so after a certain number of blocks, no accounts can send Algos to the pool.

So I want to record the percentage contribution to the pool in the local state of each sender. Meaning, if Bob contributed 10 Algos, and at expiration, the pool size is 100 Algos, Bob has 10% of the pool. The problem is that when Bob sends 10 Algos, the pool has not expired yet and can keep growing, so the percentage of contribution cannot be known until the expiration.

How do I calculate this percentage of contribution for each sender?

You can do the following:

  • in local storage of each sender: store the amount sent to the pool
  • in global storage: store the total amount sent to the pool.

When the pool is expired, anyone can compute the percentage of contribution by dividing the former by the later.
There is no need to actually store this percentage as it can be easily re-computed.

1 Like