Skip to content

Commit 40a78f0

Browse files
committed
indev
1 parent 352170c commit 40a78f0

4 files changed

Lines changed: 13 additions & 75 deletions

File tree

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ pip uninstall alpha-homora-v2
111111
112112
## Roadmap:
113113
114-
1. ***(WIP)*** Get position value of equity and debt
115-
2. ***(WIP)*** Get outstanding rewards value in native rewards token and USD
116-
3. ***(WIP)*** Get current debt ratio
117-
4. Integrate other DEXes outside of the Avalanche network
114+
1. ~~Get position value of equity and debt~~
115+
2. ~~Get current debt ratio~~
116+
3. Get outstanding rewards value in native rewards token and USD
117+
4. Get current pool APY
118+
5. Integrate with Ethereum network exchanges

alpha_homora_v2/position.py

Lines changed: 7 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ def get_debt_ratio(self) -> float:
155155

156156
return borrow_credit / collateral_credit
157157

158-
def get_position_value(self):
158+
def get_position_value(self) -> tuple[float, float, float, float, float, float]:
159159
"""
160160
Get equity, debt, and total position value in AVAX and USD.
161161
162-
:return: (dict)
162+
:return: (tuple)
163163
- equity_avax (float)
164164
- equity_usd (float)
165165
- debt_avax (float)
@@ -212,72 +212,11 @@ def get_position_value(self):
212212
total_equity_avax = position_value_avax - debt_value_avax
213213
total_equity_usd = position_value_usd - debt_value_usd
214214

215-
return {"equity_avax": total_equity_avax, "equity_usd": total_equity_usd,
216-
"debt_avax": debt_value_avax, "debt_usd": debt_value_usd,
217-
"position_avax": position_value_avax, "position_usd": position_value_usd}
218-
219-
# Deprecated but left temporarily for backup and reference:
220-
# def get_position_value(self):
221-
# """
222-
# Get equity value, debt value, and total position value in AVAX and USD.
223-
#
224-
# :return: (dict)
225-
# - equity_avax (float)
226-
# - equity_usd (float)
227-
# - debt_avax (float)
228-
# - debt_usd (float)
229-
# - position_avax (float)
230-
# - position_usd (float)
231-
# """
232-
# pool_info = self.get_pool_info()
233-
# underlying_token_data = [get_token_info_from_ref(token) for token in self.get_pool_info()['tokens']]
234-
# lp_address = pool_info['lpTokenAddress']
235-
# avax_price = get_token_price("AVAX")
236-
#
237-
# pool_instance = self.platform.get_lp_contract(lp_address)
238-
#
239-
# collateral_size = self.get_position_info()[-1]
240-
#
241-
# r0, r1, last_block_time = pool_instance.functions.getReserves().call()
242-
# supply = pool_instance.functions.totalSupply().call()
243-
#
244-
# token0_amount = (r0 * collateral_size / supply) / 10 ** int(underlying_token_data[0]['precision'])
245-
# token1_amount = (r1 * collateral_size / supply) / 10 ** int(underlying_token_data[1]['precision'])
246-
247-
# position_value_usd = token0_amount + (token1_amount * avax_price)
248-
# position_value_avax = position_value_usd * (1 / avax_price)
249-
#
250-
# print("Position Value:", position_value_usd)
251-
#
252-
# # Get debts for underlying tokens:
253-
# total_debt_usd = 0.0
254-
# total_debt_avax = 0.0
255-
# for i, token in enumerate(pool_info['tokens']):
256-
# borrow_bal = self.homora_bank.functions.borrowBalanceCurrent(self.pos_id,
257-
# Web3.toChecksumAddress(token)).call()
258-
# mtd = get_token_info_from_ref(token)
259-
# if mtd is None:
260-
# raise ValueError(f"Could not locate token metadata for {token}")
261-
#
262-
# token_price_usd = get_token_price(mtd['symbol'])
263-
#
264-
# bbal_in_token = borrow_bal / 10 ** int(mtd['precision'])
265-
# bbal_in_usd = bbal_in_token * token_price_usd
266-
# bbal_in_avax = bbal_in_token / get_token_price('AVAX')
267-
#
268-
# total_debt_usd += bbal_in_usd
269-
# total_debt_avax += bbal_in_avax
270-
#
271-
# print(f"{mtd['symbol']} | "
272-
# f"token{i}_amount: {[token0_amount, token1_amount][i]} | "
273-
# f"r{i}: {[r0, r1][i]}")
274-
#
275-
# equity_avax = position_value_avax - total_debt_avax
276-
# equity_usd = position_value_usd - total_debt_usd
277-
#
278-
# return {"equity_avax": equity_avax, "equity_usd": equity_usd,
279-
# "debt_avax": total_debt_avax, "debt_usd": total_debt_usd,
280-
# "position_avax": position_value_avax, "position_usd": position_value_usd}
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+
281220

282221
""" ------------------------------------------ UTILITY ------------------------------------------ """
283222
def get_platform(self, identifier: str) -> SpellClient:

alpha_homora_v2/resources/abi_reference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
PangolinSpellV2_ABI = 'PangolinSpellV2.json', '0x966bbec3ac35452133B5c236b4139C07b1e2c9b1'
1212
AggregatorOracle_ABI = 'AggregatorOracle.json','0xc842CC25FE89F0A60Fe9C1fd6483B6971020Eb3A'
1313
WERC20_ABI = 'WERC20ABI.json','0x496Aa991Cf3952264f284355371cD190ddcc8588'
14-
WMasterchefJoeV2_ABI = "WMasterchefJoeV2_ABI.json",'0xB41DE9c1f50697cC3Fd63F24EdE2B40f6269CBcb'
14+
WMasterchefJoeV2_ABI = "WMasterchefJoeV2_ABI.json", '0xB41DE9c1f50697cC3Fd63F24EdE2B40f6269CBcb'
1515
MasterChefJoeV2_ABI = "MasterChefJoeV2_ABI.json", "0xd6a4F121CA35509aF06A0Be99093d08462f53052"
1616
WMiniChefPNG_ABI = 'WMiniChefPNG.json', '0xa67CF61b0b9BC39c6df04095A118e53BFb9303c7'
1717
USDCe_ABI = 'USDC.e_ABI.json', '0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664'

alpha_homora_v2/spell.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ def get_pool_info(self, coll_id) -> dict:
133133
"""
134134
pid, entryRewardPerShare = self.decode_collid(coll_id)
135135
pool_info = self.staking_contract.functions.poolInfo(pid).call()
136-
# return pid, entryRewardPerShare, *pool_info
137136
return {"pid": pid, "entryRewardPerShare": entryRewardPerShare, "lpTokenAddress": pool_info[0],
138137
"allocPoint": pool_info[1], "lastRewardTimestamp": pool_info[2], "accRewardPerShare": pool_info[3],
139138
"rewarderAddress": pool_info[4]}
@@ -193,7 +192,6 @@ def get_pool_info(self, coll_id) -> dict:
193192
"""
194193
pid, entryRewardPerShare = self.decode_collid(coll_id)
195194
pool_info = self.staking_contract.functions.poolInfo(pid).call()
196-
# return pid, entryRewardPerShare, *pool_info
197195
return {"pid": pid, "entryRewardPerShare": entryRewardPerShare, "accRewardPerShare": pool_info[0],
198196
"lastRewardTimestamp": pool_info[1], "allocPoint": pool_info[2]}
199197

0 commit comments

Comments
 (0)