-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Differential Testing with --ffi flag (#60)
* Differential testing * testing framework * Workflow fixed to install python * Cleanup * Added eth-abi installation * formatting
- Loading branch information
1 parent
fbad20c
commit d340c79
Showing
3 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import sys | ||
from eth_abi import encode | ||
|
||
PRECISION = 10 ** 18 | ||
SECONDS_PER_DAY = 86400 | ||
PER_PERIOD_DECAY_PERCENT = 50 | ||
PER_PERIOD_DECAY_PERCENT_WAD = int(PER_PERIOD_DECAY_PERCENT * PRECISION / 100) | ||
|
||
class DecayedPriceCalculator: | ||
@staticmethod | ||
def decayed_premium(start_premium, elapsed_seconds): | ||
ratio = elapsed_seconds / SECONDS_PER_DAY | ||
percent_wad_remaining_per_period = (PRECISION - PER_PERIOD_DECAY_PERCENT_WAD) / PRECISION | ||
multiplier = (percent_wad_remaining_per_period ** ratio) | ||
price = (start_premium * multiplier) | ||
return int(price) | ||
|
||
@classmethod | ||
def calculate_from_cli(cls): | ||
if len(sys.argv) != 3: | ||
print("Usage: python3 price.py <start_premium> <elapsed_seconds>") | ||
sys.exit(1) | ||
|
||
start_premium = int(sys.argv[1]) | ||
elapsed_seconds = int(sys.argv[2]) | ||
|
||
result = cls.decayed_premium(start_premium, elapsed_seconds) | ||
enc = encode(['uint256'], [result]) | ||
print("0x" + enc.hex()) | ||
|
||
if __name__ == "__main__": | ||
DecayedPriceCalculator.calculate_from_cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters