Skip to content

Commit 61ef36f

Browse files
committed
indev
1 parent f5915bf commit 61ef36f

4 files changed

Lines changed: 54 additions & 65 deletions

File tree

README.md

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
<a href ="https://homora-v2.alphaventuredao.io/"><img src="img/ahv2.png" alt="Alpha Homora V2 Logo" height="200"></a>
44
<br></br>
55
<h2 align="center"><strong>Alpha-Homora-V2-Python</strong></h2>
6+
<a href="https://homora-v2.alphaventuredao.io/"><img src="https://img.shields.io/website?down_color=red&down_message=Disconnected&label=Alpha%20Homora%20V2&up_color=blue&up_message=Online&url=https%3A%2F%2Fhomora-v2.alphaventuredao.io%2F"/></a>
7+
<img src="https://img.shields.io/badge/Python-3.9%2B-yellow"/>
8+
<a href="https://github.com/PathX-Projects/Alpha-Homora-V2-Python/issues"><img src="https://img.shields.io/github/issues/PathX-Projects/Alpha-Homora-V2-Python?color=red"/></a>
69
<p align="center">
7-
A Python3.9+ package that models open Alpha Homora V2 positions to simplify interaction with their smart contracts in your Python projects.
10+
A Python3.9+ package that wraps Alpha Homora V2 positions to simplify interaction with their smart contracts in your Python projects.
811
</p>
912
<h3><strong>Current Features</strong></h3>
10-
<i>Rewards Value | Position Value | Debt & Leverage Ratio | Pool Info | <del>Current APY</del></i><br>
13+
<i>Rewards Value | Position Value | Debt & Leverage Ratio | Pool Info | Current APY</i><br>
1114
<i>Harvest Rewards | Close Position | Add & Remove Liquidity</i><br>
1215
<h3><strong>Current Supported Networks</strong></h3>
1316
<i>Avalanche</i><br>
@@ -54,7 +57,7 @@ How to use the package:
5457

5558
1. Import the AvalanchePosition class into your Python script:
5659
```python
57-
from alpha_homora_v2.position import AvalanchePosition
60+
from alpha_homora_v2 import AvalanchePosition
5861
```
5962

6063
2. **(Optional)** Instantiate your custom Web3 provider object to interact with the network:
@@ -105,10 +108,31 @@ How to use the package:
105108
# NOTE: Passing the private key is optional, but required if you want to use transactional methods on the returned AvalanchePosition object(s).
106109
```
107110
5. Use your position instance(s) to interact with the Alpha Homora V2 position smart contracts on the network:
111+
- Transactional Methods:
112+
- Return a [TransactionReceipt](alpha_homora_v2/receipt.py) object upon success
113+
- Private wallet key ***required*** for use to sign transactions
114+
- See the documentation in the [AvalanchePosition](alpha_homora_v2/position.py) class for function parameters.
115+
```python
116+
# Add liquidity to the LP
117+
position.add(params)
118+
119+
# Remove liquidity from the LP
120+
position.remove(params)
121+
122+
# Harvest available rewards:
123+
position.harvest()
124+
125+
# Close the position:
126+
position.close()
127+
```
108128
- Informational Methods
109129
- Return JSON data
110130
- Private wallet key ***not required*** for use
131+
- See [`examples/position_info.ipynb`](examples\avalanche\position_info.ipynb) for output examples.
111132
```python
133+
# Get position value (equity, debt, and position value):
134+
position.get_position_value()
135+
112136
# Get value of harvestable rewards:
113137
position.get_rewards_value()
114138

@@ -118,25 +142,23 @@ How to use the package:
118142
# Get the current leverage ratio:
119143
position.get_leverage_ratio()
120144

121-
# Get position value (equity, debt, and position value):
122-
position.get_position_value()
123-
124-
# (WIP) Get current pool APY (Only returns trading and farmng APY)
145+
# Get current pool APY
125146
position.get_current_apy()
126147

148+
# Get underlying tokens and LP for the pool:
149+
position.get_pool_tokens()
150+
151+
# Get the debt of each token in the position (token, debt_uint256, debt_token, debt_usd):
152+
position.get_tokens_debts()
153+
# Alternatively, get the debt of a single token:
154+
position.get_token_debts(token_address)
155+
156+
# Get all token borrow rates from CREAM:
157+
position.get_cream_borrow_rates()
158+
127159
# get LP pool info:
128160
position.pool
129161
```
130-
- Transactional Methods:
131-
- Return a [TransactionReceipt](alpha_homora_v2/receipt.py) object upon success
132-
- Private wallet key ***required*** for use to sign transactions
133-
```python
134-
# Harvest available rewards:
135-
position.harvest()
136-
137-
# Close the position:
138-
position.close()
139-
```
140162
141163
## Uninstallation:
142164

alpha_homora_v2/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
from .position import AvalanchePosition
2+
13
__version__ = "2.0.0"
24

alpha_homora_v2/position.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def __init__(self, position_id: int, owner_wallet_address: str, owner_private_ke
4545

4646
self._oracle = AvalancheSafeOracle()
4747

48-
""" ------------------------------------------ PRIMARY ------------------------------------------ """
48+
""" -------------------- TRANSACTIONAL METHODS: -------------------- """
49+
4950
def add(self,
5051
tokenA_data: tuple[ARC20Token, float, float] = None,
5152
tokenB_data: tuple[ARC20Token, float, float] = None,
@@ -61,6 +62,8 @@ def add(self,
6162
(ARC20Token, supply_amount, borrow_amount)
6263
:param tokenLP_data: The LP token if supplying, supply amount, and borrow amount (optional)
6364
(ARC20Token object, supply_amount, borrow_amount)
65+
66+
:return: TransactionReceipt object
6467
"""
6568
self._has_private_key()
6669

@@ -115,6 +118,8 @@ def remove(self, pct_position_size: float,
115118
:param tokenB_data: The second underlying (or native) token in the pool, and the percentage of this token debt to repay (e.g. 0.50 = 50% of USDC debt)
116119
(ARC20Token, pct_amount_repay) (optional)
117120
:param amount_lp_withdraw: (Advanced) The amount of LP token to withdraw
121+
122+
:return: TransactionReceipt object
118123
"""
119124
self._has_private_key()
120125

@@ -148,9 +153,7 @@ def close(self) -> TransactionReceipt:
148153
"""
149154
Close the position if it is open
150155
151-
Returns:
152-
- transaction hash
153-
- transaction receipt
156+
:return: TransactionReceipt object
154157
"""
155158
self._has_private_key()
156159

@@ -180,9 +183,9 @@ def harvest(self) -> Union[TransactionReceipt, None]:
180183
181184
Returns:
182185
if there are rewards to harvest:
183-
- transaction hash (str)
184-
- transaction receipt (AttributeDict)
185-
else None
186+
- TransactionReceipt object
187+
else:
188+
- None
186189
"""
187190
self._has_private_key()
188191

@@ -195,6 +198,8 @@ def harvest(self) -> Union[TransactionReceipt, None]:
195198

196199
return self._sign_and_send(encoded_bank_func)
197200

201+
""" -------------------- INFORMATIONAL METHODS: -------------------- """
202+
198203
def get_rewards_value(self) -> dict: # tuple[float, float, str, str]
199204
"""
200205
Get the amount of outstanding yield farming rewards in the position.
@@ -403,7 +408,7 @@ def get_token_debts(self) -> list[tuple[ARC20Token, int, float, float]]:
403408

404409
return debt_output
405410

406-
""" ------------------------------------------ UTILITY ------------------------------------------ """
411+
""" -------------------- UTILITY METHODS: -------------------- """
407412

408413
def get_token_borrow_balance(self, token_address: str):
409414
return self._homora_bank.functions.borrowBalanceCurrent(self.pos_id, Web3.toChecksumAddress(token_address)).call()

dev/borrowAPY_calculation.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)