unlock-protocol / locked.fyi

A basic notes application where notes are stored on IPFS and only visible by members of a lock
https://locked.fyi/
MIT License
21 stars 7 forks source link

Adding price-rounding functionality #56

Closed nfurfaro closed 4 years ago

nfurfaro commented 4 years ago

Rounds the price to the nearest 1/10 of 1 Dai. eg: while s=29 - 35, p= 1.500000000000000000 // unrounded = 1.53148... while s=36 - 44, p= 1.600000000000000000 // unrounded = 1.55630

Also cleans up some comments and unneeded stuff from the contract.

The last remaining addition to the contract (apart from possible gas-optimizations) is to add the call to the DAO contract to initiate minting an FYI token for the author.

Next steps are: 3.) take a closer look at how to get the DAO to do what we need it to do 4.) add the call to the DAO in the hook 5.) deploy rinkeby test system

Note on gas: Base case (No hook) for purchase: values are: Min, Max, Average, # of calls, cost $

![IMAGE](quiver-image-url/BAFB1CBD1EB78D39C9924213036A0A47.jpg =1522x57) image

With the hook: No price update: 199358 gas for a first key, 109577 gas for a key extension With price update: 225561 gas for a first key, 135768 gas for a key extension

So, around 26,000 extra gas for updating the price (which we're doing far less often now). For reference, it costs:

Overall, even for our worst-case scenario(first time key purchase with a price update), we're well below the max values for the purchase function without even using the hook!