forked from Badger-Finance/badger-multisig
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Citadel-DAO/issue/10_args_to_csv
feat: dump sablier args back to csv
- Loading branch information
Showing
3 changed files
with
27 additions
and
37 deletions.
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 |
---|---|---|
@@ -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) |
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 |
---|---|---|
@@ -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 |