Let's say I have 5 contributors to a pool of a smart contract. They all contributed 1 ether. The smart contract lost 2 ether, and now I want to transfer back the remaining 3 ether to the 5 contributors but also refund the delta of the loss.

How can I mathematically define to refund the delta? do I need to use modulus?

  • I believe the question is a bit abstract. In the end, do you want do refund 5 ETH to the contributors (which is exactly what they deposited collectively)? The "delta" you refer to equals 2 in your example? – Daniel Portugal Jul 18 '19 at 16:48
  • exactly. Somehow 2 ether (the delta) was lost from the pool; the contributors all lost 0.25 ether individually from their initial contribution. I want to mathematically calculate this 0.25 ether individual loss and add it to the transfer. – NowsyMe Jul 18 '19 at 16:54

You didn't explain the periodicity and other details.

  1. Is the membership fixed or do they come and go?
  2. Does the contract continue to gain/lose on operations, or is this a wrap-up and final settlement?

In the simplest case I can think of, all members join (deposit), then things happen, then you establish the entitlement of each member at a point in time and stop gains/losses. You let them each withdraw 3/5 (0.6) of an ether.

A more fluid arrangement would involve the use of tokens. You sell tokens to yourself for 1 ether to bootstrap things with a "par" value of 1 ether/token. Then the contract offers to buy (redemption) or sell (issuance) at a price set by a formula. Mintable and burnable token design allows for as many tokens as people want to buy and destroys them on redemption.

The price would be

ether on hand/tokens in circulation

So, with 3 ether on hand and 5 tokens in circulation, the price would be 3/5 (0.6) ether for 1 token. Someone will redeem a token for 3/5 (0.6) ether, leaving 2.4 ether on hand and 4 tokens outstanding. Someone else sells and they get 1/4 of 2.4 which is also 0.6 (as it should be).

Members would join and leave as/when they wish (by purchasing and redeeming tokens). The operations and subsequent gains/losses would be continuous with no need for cut-off times in the calculation. A caveat would be that the world of off-chain assets is not so tidy.

Not legal advice. Not investment advice. Check the math. Your mileage may vary. Void where prohibited.

  • thanks for the in-depth answer, I will edit my question to be more detailed apparently I'm not being verbose enough in my example – NowsyMe Jul 18 '19 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.