Scenario: Implement a robust system to monitor USDT transfer to the ZERO address (https://etherscan.io/address/0x0000000000000000000000000000000000000000) on Ethereum mainnet. In case the transfer happens, our team would like to be notified to take appropriate actions. Design the system, such that:
- Once the token transfer event happens, our team gets notified within 2 minutes.
- Resilient โ No downtime
- Cost-effective
- Can easily be modified to add more token transfer monitorings (e.g. to other addresses, or monitor other token addresses)
overview of the algorithm or approaches used), including the analysis of why the design is good, compared to other possible designs.
proposed may have (that may cause the monitoring to not function properly).
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()
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:
- Increase shares by XX, or
- 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 }