Skip to content

Commit

Permalink
one more shot, back to floats and quantize.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tritium-VLK committed Aug 23, 2024
1 parent a9ab982 commit d02804a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 9 additions & 2 deletions automation/lstGrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
from bal_tools import Subgraph
from bal_addresses import to_checksum_address

precision = Decimal(
"0." + "0" * 9 + "1"
) # 10 0s after the dot is insignificant for our purposes and takes care of rounding errors.


# import boost_data, cap_override_data and fixed_emissions_per_pool from the python file specified in POOL_CONFIG
pool_config = importlib.import_module(f"automation.{FILE_PREFIX}")
total_fixed_emissions = pool_config.total_fixed_emissions
Expand Down Expand Up @@ -159,7 +164,7 @@ def recur_distribute_unspend_tokens(
total_uncapped_weight = Decimal(
sum(
[
g["voteWeight"]
g["voteWeight"].quantize(precision, rounding=ROUND_DOWN)
for g in [
gauge
for addr, gauge in tokens_gauge_distributions.items()
Expand Down Expand Up @@ -194,7 +199,9 @@ def recur_distribute_unspend_tokens(
distribution = min(
Decimal(uncap_gauge["distribution"])
+ unspent_tokens
* Decimal(uncap_gauge["voteWeight"])
* Decimal(uncap_gauge["voteWeight"]).quantize(
precision, rounding=ROUND_DOWN
)
/ total_uncapped_weight,
max_tokens_per_pool[a],
)
Expand Down
8 changes: 5 additions & 3 deletions automation/payload_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def generate_and_save_aura_transaction(
tx["contractInputsValues"]["_pid"] = aura_pid
amount = (
Decimal(gauge["distroToAura"]) * Decimal(pct_of_distribution)
).to_integral_value(rounding=ROUND_DOWN)
wei_amount = amount * Decimal(1e18)
).quantize(precision, rounding=ROUND_DOWN)
wei_amount = (amount * Decimal(1e18)).to_integral_value()
tx["contractInputsValues"]["_amount"] = str(wei_amount)
tx["contractInputsValues"]["_periods"] = str(num_periods)
if wei_amount > 0:
Expand Down Expand Up @@ -99,7 +99,9 @@ def generate_and_save_bal_injector_transaction(
# Inject list of gauges addresses:
for gauge in gauge_distributions:
gauges_list.append(gauge["recipientGaugeAddr"])
epoch_amount = Decimal(gauge["distroToBalancer"]) * Decimal(pct_of_distribution)
epoch_amount = (
Decimal(gauge["distroToBalancer"]) * Decimal(pct_of_distribution)
).quantize(precision, rounding=ROUND_DOWN)
period_amount = epoch_amount / Decimal(num_periods)
wei_amount = (period_amount * Decimal(1e18)).to_integral_value(
rounding=ROUND_DOWN
Expand Down

0 comments on commit d02804a

Please sign in to comment.