Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dump sablier args back to csv #14

Merged
merged 1 commit into from May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion helpers/addresses.py
Expand Up @@ -27,8 +27,9 @@
"citadel": {
"deployer": "0xa967ba66fb284ec18bbe59f65bcf42dd11ba8128",
"governance": "0xa95ecbDc51082ED2a2D078a5dE5275777dD73347",
"treasury_vault": "0x38724146C8dc1Aa49c3395091cf86B789c37F52c",
"policy_ops": "0x7426e8987f8d388e731Dec452D8B0a1710d8E416",
"treasury_vault": "0x38724146C8dc1Aa49c3395091cf86B789c37F52c",
"treasury_ops": "0x7426e8987f8d388e731Dec452D8B0a1710d8E416", # TODO
"gac": "0xd93550006e351161a6edff855fc3e588c46ecfb1",
"funding": {
"wbtc": "0x2559F79Ffd2b705083A5a23f1fAB4bB03C491435",
Expand Down
51 changes: 20 additions & 31 deletions scripts/sablier/create_streams.py
@@ -1,59 +1,48 @@
from datetime import datetime
from datetime import timezone
import os
import numpy as np
import pandas as pd

from great_ape_safe import GreatApeSafe
from helpers.addresses import registry


def main(csv_file="stream_recipients_example"):
safe = GreatApeSafe(registry.eth.citadel.policy_ops)
safe = GreatApeSafe(registry.eth.citadel.treasury_ops) # vault?
safe.init_sablier()

df = pd.read_csv(f"{os.path.dirname(__file__)}/{csv_file}.csv")
df = pd.read_csv(
f"{os.path.dirname(__file__)}/{csv_file}.csv",
parse_dates=['start_time', 'end_time']
)

df["ts_start"] = df['start_time'].astype(np.int64) // 10 ** 9
df["ts_end"] = df['end_time'].astype(np.int64) // 10 ** 9
df["interval"] = df["ts_end"] - df["ts_start"]

df["stream_amount"] = df.apply(
df["streamable_mantissa"] = df.apply(
lambda row: row["stream_amount"]
* 10 ** safe.contract(row["token_address"]).decimals(),
axis=1,
)
df["stream_amount"].mask(
df["stream_amount"]
% (
df["ending_time"].apply(lambda x: _date_to_ts(x))
- df["start_time"].apply(lambda x: _date_to_ts(x))
)
!= 0,
_acceptable_amount(
df["stream_amount"],
df["ending_time"].apply(lambda x: _date_to_ts(x))
- df["start_time"].apply(lambda x: _date_to_ts(x)),
),
inplace=True,
df["streamable_mantissa"] = df["streamable_mantissa"].mask(
df["streamable_mantissa"] % df["interval"] != 0,
df["streamable_mantissa"] - (df["streamable_mantissa"] % df["interval"])
)

total_approval_amts = df.groupby("token_address")["stream_amount"].sum()
total_approval_amts = df.groupby("token_address")["streamable_mantissa"].sum()
for addr, amt in total_approval_amts.items():
erc20 = safe.contract(addr)
erc20.approve(safe.sablier.sablier_v1_1, amt)

df.to_csv(f"{os.path.dirname(__file__)}/{csv_file}_processed.csv", index=False)

for _, row in df.iterrows():
safe.sablier.create_stream(
row["recipient"],
row["stream_amount"],
row["streamable_mantissa"],
row["token_address"],
_date_to_ts(row["starting_time"]),
_date_to_ts(row["ending_time"]),
row["ts_start"],
row["ts_end"]
)

safe.post_safe_tx()


def _date_to_ts(str_date):
dt = datetime.strptime(str_date, "%Y-%m-%d")
return int(dt.replace(tzinfo=timezone.utc).timestamp())


def _acceptable_amount(amount, interval):
return amount - (amount % interval)
10 changes: 5 additions & 5 deletions scripts/sablier/stream_recipients_example.csv
@@ -1,5 +1,5 @@
recipient,stream_amount,token_address,start_time,ending_time
0xa95ecbDc51082ED2a2D078a5dE5275777dD73347,1000,0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,2022-05-05,2022-08-05
0x38724146C8dc1Aa49c3395091cf86B789c37F52c,4000,0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,2022-05-05,2022-08-05
0xd93550006e351161a6edff855fc3e588c46ecfb1,3500,0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,2022-05-05,2022-08-05
0xd93550006e351161a6edff855fc3e588c46ecfb1,1000,0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,2022-05-05,2022-08-05
recipient,stream_amount,token_address,start_time,end_time
0xa95ecbDc51082ED2a2D078a5dE5275777dD73347,1000,0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,2022-06-01,2022-08-31
0x38724146C8dc1Aa49c3395091cf86B789c37F52c,4000,0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,2022-06-01,2022-08-31
0xd93550006e351161a6edff855fc3e588c46ecfb1,3500,0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,2022-06-01,2022-08-31
0xd93550006e351161a6edff855fc3e588c46ecfb1,1000,0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,2022-06-01,2022-08-31