Skip to content

Commit

Permalink
changed interface for solver function
Browse files Browse the repository at this point in the history
  • Loading branch information
poliwop committed Oct 23, 2024
1 parent c550eb1 commit 5aa977d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
13 changes: 11 additions & 2 deletions hydradx/model/amm/omnix_solver_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,11 @@ def find_solution3(state: OmnipoolState, intents: list, epsilon: float = 1e-5) -
return add_buy_deltas(intents, sell_deltas)


def find_solution_outer_approx(state: OmnipoolState, partial_intents: list, full_intents: list, epsilon: float = 1e-5) -> list:
def find_solution_outer_approx(state: OmnipoolState, intents: list, epsilon: float = 1e-5) -> list:
partial_intent_indices = [i for i in range(len(intents)) if intents[i]['partial']]
full_intent_indices = [i for i in range(len(intents)) if not intents[i]['partial']]
partial_intents = [intents[i] for i in partial_intent_indices]
full_intents = [intents[i] for i in full_intent_indices]

m = len(partial_intents)
r = len(full_intents)
Expand Down Expand Up @@ -904,7 +908,12 @@ def find_solution_outer_approx(state: OmnipoolState, partial_intents: list, full
sell_deltas = round_solution(partial_intents, best_intent_deltas)
partial_deltas_with_buys = add_buy_deltas(partial_intents, sell_deltas)
full_deltas_with_buys = [[-full_intents[l]['sell_quantity'], full_intents[l]['buy_quantity']] if y_best[l] == 1 else [0,0] for l in range(r)]
return partial_deltas_with_buys, full_deltas_with_buys
deltas = [None] * len(intents)
for i in range(len(partial_intent_indices)):
deltas[partial_intent_indices[i]] = partial_deltas_with_buys[i]
for i in range(len(full_intent_indices)):
deltas[full_intent_indices[i]] = full_deltas_with_buys[i]
return deltas

print(Z_U)
print(x_best)
Expand Down
7 changes: 1 addition & 6 deletions hydradx/tests/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,7 @@ def test_full_solver():
initial_state.last_fee = {tkn: mpf(0.0025) for tkn in lrna}
initial_state.last_lrna_fee = {tkn: mpf(0.0005) for tkn in lrna}

partial_intents = [i for i in intents if i['partial']]
full_intents = [i for i in intents if not i['partial']]
partial_intent_deltas, full_intent_deltas = find_solution_outer_approx(initial_state, partial_intents, full_intents)
intent_deltas = partial_intent_deltas + full_intent_deltas
intents = partial_intents + full_intents
# pprint(intent_deltas)
intent_deltas = find_solution_outer_approx(initial_state, intents)

assert validate_and_execute_solution(initial_state.copy(), copy.deepcopy(intents), intent_deltas)

Expand Down

0 comments on commit 5aa977d

Please sign in to comment.