Skip to content

Commit

Permalink
remove all the todos and make it easier to configure payload building.
Browse files Browse the repository at this point in the history
  • Loading branch information
DontNeedGithubAccount committed Jun 18, 2024
1 parent f110215 commit ba0f1b3
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 113 deletions.
4 changes: 2 additions & 2 deletions automation/arbitrum_stip_bridge_start_q2_2024.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@
{
"pool_id": "0x90e6cb5249f5e1572afbf8a96d8a1ca6acffd73900000000000000000000055c",
"meta": {"symbol": "rsETH-wETH"},
"fixedEmissions": 2000 / 2, # /2 for aura split
"fixedEmissions": 2000,
},
{
"pool_id": "0xcdcef9765d369954a4a936064535710f7235110a000200000000000000000558",
"meta": {"symbol": "weETH-wstETH ECLP"},
"fixedBoost": 1.5,
"fixedEmissions": 2000 / 2, # / 2 for aura split
"fixedEmissions": 2000,
},
]

Expand Down
65 changes: 0 additions & 65 deletions automation/aura_direct.py

This file was deleted.

6 changes: 2 additions & 4 deletions automation/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
CHAIN_NAME = "arbitrum"
CURRENT_YEAR = 2024
# How many incentives should be taken away from vote following to be distributed as fixed incentives? Per 2 week epoch
FIXED_INCENTIVE_TOKENS_PER_EPOCH = 4000 / 2 # /2 for aura split
FIXED_INCENTIVE_TOKENS_PER_EPOCH = 4000
# Total number of tokens available per 2 week epoch
TOTAL_TOKENS_PER_EPOCH = (
600_000 / (12 / 2) / 2
) # 100k per epoch, 50k per week (/2 for aura split)
TOTAL_TOKENS_PER_EPOCH = 600_000 / (12 / 2) # 100k per epoch, 50k per week
DYNAMIC_BOOST_CAP = 3
MIN_BAL_IN_USD_FOR_BOOST = 200
TOKENS_TO_FOLLOW_VOTING = TOTAL_TOKENS_PER_EPOCH - FIXED_INCENTIVE_TOKENS_PER_EPOCH
Expand Down
57 changes: 15 additions & 42 deletions automation/lstGrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
from automation.helpers import get_abi
from automation.helpers import get_block_by_ts

from .aura_direct import generate_and_save_aura_transaction
from .payload_builders import generate_and_save_aura_transaction
from .payload_builders import generate_and_save_bal_injector_transaction

# 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}")
Expand Down Expand Up @@ -198,45 +199,6 @@ def recur_distribute_unspend_tokens(
recur_distribute_unspend_tokens(max_tokens_per_pool, tokens_gauge_distributions)


def generate_and_save_transaction(
tokens_gauge_distributions: Dict, start_date: datetime, end_date: datetime
) -> Dict:
"""
Take tx template and inject data into it
"""
# Dump into output.json using:
with open(f"{get_root_dir()}/data/output_tx_template.json") as f:
output_data = json.load(f)
# Find transaction with func name `setRecipientList` and dump gauge
gauge_distributions = tokens_gauge_distributions.values()
for tx in output_data["transactions"]:
if tx["contractMethod"]["name"] == "setRecipientList":
# Inject list of gauges addresses:
tx["contractInputsValues"][
"gaugeAddresses"
] = f"[{','.join([gauge['recipientGaugeAddr'] for gauge in gauge_distributions])}]"
# Inject vote weights:
# Dividing by 2 since we are distributing for 2 weeks and 1 week is a period
tx["contractInputsValues"][
"amountsPerPeriod"
] = f"[{','.join([str(int(Decimal(gauge['distribution']) * Decimal(1e18) / 2)) for gauge in gauge_distributions])}]"
tx["contractInputsValues"][
"maxPeriods"
] = f"[{','.join(['1' for gauge in gauge_distributions])}]" ## todo 1 was changed to 2 for aura split
if tx["contractMethod"]["name"] == "transfer":
tx["contractInputsValues"]["amount"] = str(
int(Decimal(TOKENS_TO_FOLLOW_VOTING) * Decimal(1e18))
)

# Dump back to tokens_distribution_for_msig.json
with open(
f"{get_root_dir()}/output/{FILE_PREFIX}_{start_date.date()}_{end_date.date()}.json",
"w",
) as _f:
json.dump(output_data, _f, indent=4)
return output_data


def run_stip_pipeline(end_date: int) -> None:
"""
Main function to execute STIP calculations
Expand Down Expand Up @@ -431,10 +393,21 @@ def run_stip_pipeline(end_date: int) -> None:
index=False,
)

generate_and_save_transaction(gauge_distributions, start_date, end_date)
generate_and_save_bal_injector_transaction(
gauge_distributions,
start_date,
end_date,
pct_of_distribution=0.25, # 50% due to 1 week, 50% due to half aura
num_periods=1, # 1 week special
)
# TODO
# Note that this will also be for the full amount logic to split is pending, but can run for half to split the whole
# payload.
generate_and_save_aura_transaction(
gauge_distributions, start_date, end_date, CHAIN_NAME
gauge_distributions,
start_date,
end_date,
CHAIN_NAME,
pct_of_distribution=0.25, # 50% due to 1 week, 50% due to half BAL
num_periods=1, # 1 week special
)
122 changes: 122 additions & 0 deletions automation/payload_builders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
from bal_tools import Aura
import json
import os
import copy
import math
from datetime import datetime
from decimal import Decimal, ROUND_DOWN
from typing import Dict
from automation.constants import FILE_PREFIX

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


def get_root_dir() -> str:
return os.path.abspath(os.path.dirname(os.path.dirname(__file__)))


def generate_and_save_aura_transaction(
tokens_gauge_distributions: Dict,
start_date: datetime,
end_date: datetime,
chain_name: str,
pct_of_distribution: Decimal = Decimal(1),
num_periods: int = 2,
) -> Dict:
"""
Take a set of distributions and send them to aura direct
"""
aura = Aura(chain_name)
# Dump into output.json using:
with open(f"{get_root_dir()}/data/aura_direct_stream.json") as f:
output_data = json.load(f)
# Find transaction with func name `setRecipientList` and dump gauge
gauge_distributions = tokens_gauge_distributions.values()
tx_template = output_data["transactions"][1]

tx_list = []
total_amount = 0
# Inject list of gauges addresses:
for gauge in gauge_distributions:
aura_pid = aura.aura_pids_by_address.get(gauge["recipientGaugeAddr"])
if not aura_pid:
print(
f"WARNING: No aura pid found for gauge {gauge['recipientGaugeAddr']}, using gauge address in payload instead for easy debugging."
)
aura_pid = gauge["recipientGaugeAddr"]
tx = copy.deepcopy(tx_template)
tx["contractInputsValues"]["_pid"] = aura_pid
amount = (
Decimal(gauge["distribution"]) * Decimal(pct_of_distribution)
).quantize(precision, rounding=ROUND_DOWN)
wei_amount = amount * Decimal(1e18)
tx["contractInputsValues"]["_amount"] = str(wei_amount)
tx["contractInputsValues"]["_periods"] = str(num_periods)
tx_list.append(tx)
total_amount += wei_amount

# Add approve tx
approve_tx = output_data["transactions"][0]
approve_tx["contractInputsValues"]["amount"] = str(total_amount * Decimal(1e18))
tx_list.insert(0, approve_tx)
output_data["transactions"] = tx_list
with open(
f"{get_root_dir()}/output/{FILE_PREFIX}_{start_date.date()}_{end_date.date()}_aura_direct_stream.json",
"w",
) as _f:
json.dump(output_data, _f, indent=2)
print(f"{total_amount}({total_amount/Decimal(1e18)}) $ARB approved for aura direct")
return output_data


def generate_and_save_bal_injector_transaction(
tokens_gauge_distributions: Dict,
start_date: datetime,
end_date: datetime,
pct_of_distribution: Decimal = Decimal(1),
num_periods: int = 2,
) -> Dict:
"""
Take tx template and inject data into it
"""
# Dump into output.json using:
with open(f"{get_root_dir()}/data/output_tx_template.json") as f:
output_data = json.load(f)

# Find transaction with func name `setRecipientList` and dump gauge
gauge_distributions = tokens_gauge_distributions.values()
tx_template = output_data["transactions"][0]
tx_list = []
gauges_list = []
amounts_list = []
max_periods_list = []
total_amount = 0
# Inject list of gauges addresses:
for gauge in gauge_distributions:
gauges_list += gauge["recipientGaugeAddr"]
epoch_amount = (
Decimal(gauge["distribution"]) * Decimal(pct_of_distribution)
).quantize(precision, rounding=ROUND_DOWN)
period_amount = epoch_amount / Decimal(num_periods)
wei_amount = period_amount * Decimal(1e18)
total_amount += epoch_amount * Decimal(1e18)
amounts_list.append(str(wei_amount))
max_periods_list.append(str(num_periods))
tx = copy.deepcopy(tx_template)
tx["contractInputsValues"]["gaugeAddresses"] = f"[{','.join(gauges_list)}]"
tx["contractInputsValues"]["amountsPerPeriod"] = f"[{','.join(amounts_list)}]"
tx["contractInputsValues"]["maxPeriods"] = f"[{','.join(max_periods_list)}]"
tx_list.append(tx)
transfer_tx = output_data["transactions"][1]
transfer_tx["contractInputsValues"]["amount"] = str(int(total_amount))
tx_list.append(transfer_tx)
output_data["transactions"] = tx_list
with open(
f"{get_root_dir()}/output/{FILE_PREFIX}_{start_date.date()}_{end_date.date()}_bal_injector_stream.json",
"w",
) as _f:
json.dump(output_data, _f, indent=2)
print(f"{total_amount} $ARB approved for balancer injector")
return output_data

0 comments on commit ba0f1b3

Please sign in to comment.