Skip to content

Commit

Permalink
Fixed dca_with_lping strategy to take advantage of new LPing features
Browse files Browse the repository at this point in the history
  • Loading branch information
poliwop committed Aug 23, 2024
1 parent 909ab4b commit 692a1b1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
19 changes: 3 additions & 16 deletions hydradx/model/amm/trade_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,26 +1031,13 @@ def strategy(state: GlobalState, agent_id: str) -> GlobalState:
sell_quantity=agent.holdings[sell_asset] - init_sell_amt
)

# we turn off the withdrawal fee for this remove_liquidity
# this is because removing liquidity here is due to a limitation in our implementation,
# agents can have only one LP position each in one asset in Omnipool.
# In reality someone executing this strategy would simply add liquidity and get a new LP position.
withdrawal_fee_cache = pool.withdrawal_fee # hack to temporarily zero out withdrawal fee
pool.withdrawal_fee = False
if agent.is_holding((pool.unique_id, buy_asset)):
# remove all liquidity in buy_asset
pool.remove_liquidity(
agent=agent,
quantity=agent.holdings[(pool.unique_id, buy_asset)],
tkn_remove=buy_asset
)
pool.withdrawal_fee = withdrawal_fee_cache

# LP the buy asset
nft_id = str(len(agent.nfts) + 1)
pool.add_liquidity(
agent=agent,
quantity=agent.holdings[buy_asset] - init_buy_amt,
tkn_add=buy_asset
tkn_add=buy_asset,
nft_id=nft_id
)

return state
Expand Down
4 changes: 1 addition & 3 deletions hydradx/tests/test_omnipool_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,8 @@ def test_dca_with_lping(
strategy.execute(state, trader_id)

if init_sell_tkn_lped > 0:
if ('omnipool', buy_tkn) not in agent.holdings:
if len(agent.nfts) == 0:
raise AssertionError('Agent does not have shares for buy_tkn.')
if agent.holdings[('omnipool', buy_tkn)] == init_buy_tkn_lped:
raise AssertionError('Agent did not receive shares for buy_tkn.')

lp_diff = init_sell_tkn_lped
if ('omnipool', sell_tkn) in agent.holdings:
Expand Down

0 comments on commit 692a1b1

Please sign in to comment.