Skip to content

Commit

Permalink
refactoring _solve_inclusion_problem to use precalculated values in I…
Browse files Browse the repository at this point in the history
…CEProblem object
  • Loading branch information
poliwop committed Oct 30, 2024
1 parent 4687781 commit 07c4bec
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions hydradx/model/amm/omnix_solver_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,6 @@ def _solve_inclusion_problem(
old_A_upper = None,
old_A_lower = None
):
state = p.omnipool
asset_list = p.asset_list
tkn_list = ["LRNA"] + asset_list
n, m, r = p.n, p.m, p.r
Expand Down Expand Up @@ -594,19 +593,20 @@ def _solve_inclusion_problem(
partial_intent_sell_amts = p.get_partial_sell_maxs_scaled()
upper = np.array([inf] * 4 * n + partial_intent_sell_amts + [1] * r)

# we will temporarily assume a 0 solution is latest, and linearize g() around that.
S = np.zeros((n, k))
S_upper = np.zeros(n)
S_lower = np.array([-inf]*n)
grads = np.zeros(2*n)
for i in range(n):
grads[i] = -scaling["LRNA"] * state.liquidity[asset_list[i]] - scaling["LRNA"] * scaling[asset_list[i]] * x[n+i]
grads[n+i] = -scaling[asset_list[i]] * state.lrna[asset_list[i]] - scaling["LRNA"] * scaling[asset_list[i]] * x[i]
for i, tkn in enumerate(asset_list):
lrna_c = p.get_amm_lrna_coefs()
asset_c = p.get_amm_asset_coefs()
grads[i] = -lrna_c[tkn] - lrna_c[tkn] * asset_c[tkn] * x[n+i]
grads[n+i] = -asset_c[tkn] - lrna_c[tkn] * asset_c[tkn] * x[i]
S[i, i] = grads[i]
S[i, n+i] = grads[n+i]
S_upper[i] = (grads[i] * x[n+i] + grads[n+i] * x[n+i] + scaling["LRNA"] * state.liquidity[asset_list[i]] * x[i]
+ scaling[asset_list[i]] * state.lrna[asset_list[i]] * x[n+i]
+ scaling["LRNA"] * scaling[asset_list[i]] * x[i] * x[n+i])
grad_dot_x = grads[i] * x[i] + grads[n+i] * x[n+i]
g_neg = lrna_c[tkn] * x[i] + asset_c[tkn] * x[n+i] + lrna_c[tkn] * asset_c[tkn] * x[i] * x[n+i]
S_upper[i] = grad_dot_x + g_neg

# asset leftover must be above zero
A3 = p._profit_A.toarray()
Expand Down

0 comments on commit 07c4bec

Please sign in to comment.