Skip to content

Commit 44a3189

Browse files
committed
Added optional private key for data methods
1 parent 40a78f0 commit 44a3189

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

alpha_homora_v2/position.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
class AlphaHomoraV2Position:
1919
def __init__(self, web3_provider: Web3, position_id: int, dex: str, owner_wallet_address: str,
20-
owner_private_key: str, position_type: str = "Yield Farming"):
20+
owner_private_key: str = None, position_type: str = "Yield Farming"):
2121
"""
2222
:param web3_provider: The Web3 object used to interact with the Alpha Homora V2 position's chain
2323
(ex. Web3(Web3.HTTPProvider(your_network_rpc_url)))
@@ -52,6 +52,7 @@ def close(self) -> tuple[str, dict]:
5252
- transaction hash
5353
- transaction receipt
5454
"""
55+
self.has_private_key()
5556

5657
pool_info = self.get_pool_info()
5758

@@ -93,6 +94,7 @@ def claim_all_rewards(self) -> Union[tuple[str, dict], None]:
9394
- transaction receipt (AttributeDict)
9495
else None
9596
"""
97+
self.has_private_key()
9698

9799
try:
98100
if self.get_rewards_value()[0] == 0:
@@ -117,7 +119,7 @@ def claim_all_rewards(self) -> Union[tuple[str, dict], None]:
117119

118120
return tx_hash, receipt
119121

120-
def get_rewards_value(self) -> tuple[float, float, str, str]:
122+
def get_rewards_value(self) -> dict: # tuple[float, float, str, str]
121123
"""
122124
Get the amount of outstanding yield farming rewards in the position.
123125
@@ -143,9 +145,11 @@ def get_rewards_value(self) -> tuple[float, float, str, str]:
143145

144146
reward_token_symbol, reward_token_address = [v for k, v in self.get_pool_info()["exchange"]["reward"].items()]
145147

146-
reward_value = reward_amount * get_token_price(reward_token_symbol)
148+
reward_usd = reward_amount * get_token_price(reward_token_symbol)
147149

148-
return reward_amount, reward_value, reward_token_address, reward_token_symbol
150+
# return reward_amount, reward_usd, reward_token_address, reward_token_symbol
151+
return {"reward_token": reward_amount, "reward_usd": reward_usd, "reward_token_address": reward_token_address,
152+
"reward_token_symbol": reward_token_symbol}
149153

150154
def get_debt_ratio(self) -> float:
151155
"""Return the position's debt ratio percentage in decimal form (10% = 0.10)"""
@@ -155,7 +159,7 @@ def get_debt_ratio(self) -> float:
155159

156160
return borrow_credit / collateral_credit
157161

158-
def get_position_value(self) -> tuple[float, float, float, float, float, float]:
162+
def get_position_value(self) -> dict:
159163
"""
160164
Get equity, debt, and total position value in AVAX and USD.
161165
@@ -212,10 +216,10 @@ def get_position_value(self) -> tuple[float, float, float, float, float, float]:
212216
total_equity_avax = position_value_avax - debt_value_avax
213217
total_equity_usd = position_value_usd - debt_value_usd
214218

215-
return total_equity_avax, total_equity_usd, debt_value_avax, debt_value_usd, position_value_avax, position_value_usd
216-
# return {"equity_avax": total_equity_avax, "equity_usd": total_equity_usd,
217-
# "debt_avax": debt_value_avax, "debt_usd": debt_value_usd,
218-
# "position_avax": position_value_avax, "position_usd": position_value_usd}
219+
# return total_equity_avax, total_equity_usd, debt_value_avax, debt_value_usd, position_value_avax, position_value_usd
220+
return {"equity_avax": total_equity_avax, "equity_usd": total_equity_usd,
221+
"debt_avax": debt_value_avax, "debt_usd": debt_value_usd,
222+
"position_avax": position_value_avax, "position_usd": position_value_usd}
219223

220224

221225
""" ------------------------------------------ UTILITY ------------------------------------------ """
@@ -275,6 +279,8 @@ def sign_and_send(self, function_call: ContractFunction):
275279
"""
276280
:param function_call: The uncalled and prepared contract method to sign and send
277281
"""
282+
self.has_private_key()
283+
278284
txn = function_call.buildTransaction({"nonce": self.w3_provider.eth.get_transaction_count(self.owner),
279285
"from": self.owner})
280286
signed_txn = self.w3_provider.eth.account.sign_transaction(
@@ -306,4 +312,10 @@ def decode_transaction_data(self, transaction_address: Optional) -> tuple:
306312

307313
encoded_contract_data = decoded_bank_transaction[1]['data']
308314

309-
return decoded_bank_transaction, self.platform.spell_contract.decode_function_input(encoded_contract_data)
315+
return decoded_bank_transaction, self.platform.spell_contract.decode_function_input(encoded_contract_data)
316+
317+
def has_private_key(self):
318+
if self.private_key is None:
319+
raise Exception("This method requires the position holder's private key to sign the transaction.\n"
320+
"Please set a value for the 'owner_private_key' class init attribute.")
321+

0 commit comments

Comments
 (0)