Skip to content

Commit 5b0abdd

Browse files
authored
Add buyback runlogs (#1733)
1 parent 2196daa commit 5b0abdd

File tree

3 files changed

+94
-4
lines changed

3 files changed

+94
-4
lines changed

brownie/buyback.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,14 @@ def build_buyback_tx(max_dollars=5000, max_slippage=2.0, with_fork=True):
4444
"""
4545
buyback = BUYBACK_CONTRACT
4646
treasuryBps = BUYBACK_CONTRACT.treasuryBps()
47-
ousd_for_treasury = max_dollars * treasuryBps / 10**4
48-
ousd_to_swap = max_dollars - ousd_for_treasury
49-
50-
5147

5248
# Calculate buyback amount
5349
ousd_available = ousd.balanceOf(buyback)
5450
buyback_amount = min(ousd_available, int(max_dollars * 10**18))
5551

52+
ousd_for_treasury = buyback_amount * treasuryBps / 10**4
53+
ousd_to_swap = buyback_amount - ousd_for_treasury
54+
5655
# Calculate returned OGV
5756
no_slippage_ogv = sim_buyback_ogv(10**18) * buyback_amount / 10**18
5857
expected_slippage_ogv = sim_buyback_ogv(buyback_amount)

brownie/oneinch.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from world import *
2+
import requests
3+
from types import SimpleNamespace
4+
5+
def get_1inch_swap_data(from_token, to_token, swap_amount, slippage, from_address=STRATEGIST, to_address=STRATEGIST):
6+
req = requests.get('https://api.1inch.io/v5.0/1/swap', params={
7+
'fromTokenAddress': from_token,
8+
'fromAddress': from_address,
9+
'destReceiver': to_address,
10+
'toTokenAddress': to_token,
11+
'amount': str(swap_amount),
12+
'allowPartialFill': True,
13+
'disableEstimate': 'true',
14+
'slippage': slippage
15+
}, headers={
16+
'accept': 'application/json'
17+
})
18+
19+
if req.status_code != 200:
20+
print(req.json())
21+
raise Exception("Error calling 1inch api")
22+
23+
result = req.json()
24+
25+
return SimpleNamespace(receiver = result['tx']['to'], input = result['tx']['data'])

brownie/runlogs/2023_08_strategist.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,69 @@
1919
print("Profit", "{:.6f}".format(profit / 10**18), profit)
2020
print("Vault Change", "{:.6f}".format(vault_change / 10**18), vault_change)
2121
print("-----")
22+
23+
# -----------------------------------
24+
# August 03, 2023 - OGV Buyback
25+
# -----------------------------------
26+
from buyback import *
27+
28+
def main():
29+
build_buyback_tx(max_dollars=2250, max_slippage=1.5, with_fork=True)
30+
31+
# -----------------------------------
32+
# August 03, 2023 - CVX Buyback
33+
# -----------------------------------
34+
from world import *
35+
from oneinch import get_1inch_swap_data
36+
37+
txs = []
38+
def main():
39+
with TemporaryFork():
40+
slippage = 1
41+
42+
oeth_balance = oeth.balanceOf(STRATEGIST)
43+
ousd_balance = ousd.balanceOf(STRATEGIST)
44+
45+
# Approve 1-inch to move OETH and OUSD
46+
txs.append(
47+
oeth.approve(ROUTER_1INCH_V5, oeth_balance, {'from': STRATEGIST})
48+
)
49+
txs.append(
50+
ousd.approve(ROUTER_1INCH_V5, ousd_balance, {'from': STRATEGIST})
51+
)
52+
53+
# Swap OETH for CVX
54+
txs.append(
55+
get_1inch_swap_data(
56+
OETH,
57+
CVX,
58+
oeth_balance,
59+
slippage,
60+
)
61+
)
62+
63+
# Swap OUSD for CVX
64+
txs.append(
65+
get_1inch_swap_data(
66+
OUSD,
67+
CVX,
68+
ousd_balance,
69+
slippage,
70+
)
71+
)
72+
73+
print("Schedule the following transactions on Gnosis Safe")
74+
for idx, item in enumerate(txs):
75+
print("Transaction ", idx)
76+
print("To: ", item.receiver)
77+
print("Data (Hex encoded): ", item.input, "\n")
78+
79+
80+
# -----------------------------------
81+
# August 03, 2023 - OGV Buyback 2
82+
# -----------------------------------
83+
from buyback import *
84+
85+
txs = []
86+
def main():
87+
build_buyback_tx(max_slippage=1.5, with_fork=True)

0 commit comments

Comments
 (0)