Skip to content

tahmidbintaslim/Web3-Reward-Algo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Task 2 โ€“ Reward Distribution

Q3: Write a Python3 code that calculates how much each user should receive the reward.

Please include any test cases to test the functionality, including normal and edge cases as well.

Implement the Python function according to the format below: def calculate_reward(events: list[tuple[str,int]]) -> dict[str, float]: raise NotImplemented()

TODO

Problem statement: We have 10,000 USDT to be distributed to our users who use our lending protocol during the timestamp 0 to 3600 (1 hour duration). The reward distribution algorithm is such that the 1000 tokens are distributed at the rate of ~2.778 USDT / sec, where at each point in time, the tokens will be distributed proportionally based on the total number of userโ€™s shares. Each userโ€™s action can either be:

  1. Increase shares by XX, or
  2. Decrease shares by YY (userโ€™s shares can never be negative)

Example: โ— User action events โ€“ format will be a list of tuples of (user, timestamp, share_adjust): โ—‹ [ (โ€œAโ€, 0, 2), (โ€œBโ€, 2, 1), (โ€œAโ€, 10, -1) ] The above example list of events means that

  • User A increases 2 shares at time t=0
  • User B increases 1 share at time t=2
  • User A decreases 1 share at time t=10

So,

  • Between time t=0 & t=1, only user A is getting the rewards โ†’ A gets 2.778 USDT
  • Between time t=1 & t=10, A has 2 shares, while B has 1 share โ†’ A gets 2โ„3 of whatโ€™s distributed, and B gets 1โ„3 of whatโ€™s distributed โ†’ A gets 16.667 USDT and B gets 8.333 USDT
  • Between time t=10 & t=3600, A and B has 1 share each โ†’ A gets 1โ„2 of whatโ€™s distributed, and B gets 1โ„2 of whatโ€™s distributed โ†’ A and B each gets 4986.111 USDT So, in total, A gets 5005.556 USDT and B gets 4994.444 USDT Expected Output: a dictionary of {โ€œAโ€ : 5005.556, โ€œBโ€ : 4994.444 }

About

Well, its kinda test ๐Ÿ˜‚

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages