@naviprotocol/multiply 0.2.0-preview.20261124.1 → 0.2.0-preview.20261124.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.js CHANGED
@@ -1,62 +1,62 @@
1
- import { validateMarketMode as z, assertModeExposure as me } from "./emode.js";
2
- import { voloConverter as Se, haedalConverter as Ue, astrosConverter as Le, validateConversion as De } from "./converters.js";
3
- import { defaultClient as Re, createNaviDataSource as je } from "./data-source.js";
4
- import { strategies as Ve } from "./strategies.js";
5
- import { indexRegistryStrategies as Pe, registryKeyString as N, normalizeCapRegistry as ye, MAINNET_CAP_REGISTRY as Me, normalizeEnv as Qe, assertRegistryUsable as fe, accountCapType as Ce, registerCreatedCapPTB as $e } from "./cap-registry.js";
6
- import { validateAction as Te, plan as Fe, metrics as ve, chooseConversion as Be } from "./planner.js";
7
- import { positionSides as ae, atomPrices as Ke, isDustClose as M, tokenDecimals as U, leverageCeiling as be, amountCushion as Ae, withinLtv as Ge, supplyCapacity as ze, borrowCapacity as qe, withinSameReserveCapacity as Ye } from "./amounts.js";
8
- import { check as o, jsonCopy as D, coinType as Q, sameCoin as k, address as _, uint as q, BN as m, checksum as R, assertAddressPTB as Xe, minOutputGuard as oe } from "./utils.js";
9
- import { validateFunding as He } from "./funding.js";
10
- function rt(C = {}) {
11
- const $ = C.client ?? Re(), ne = C.converters ?? [Se({ client: $ }), Ue({ client: $ })], re = C.fallbackConverter ?? Le({ services: C.services, client: $ }), F = /* @__PURE__ */ new Map();
12
- for (const e of [...ne, re])
13
- o(!F.has(e.id), "INVALID_ARGUMENT", `Duplicate converter id: ${e.id}`), F.set(e.id, e);
14
- const j = (C.strategies ?? Object.values(Ve)).map(
15
- (e) => le(D(e))
1
+ import { validateMarketMode as q, assertModeExposure as Ce } from "./emode.js";
2
+ import { voloConverter as Ue, haedalConverter as Le, astrosConverter as De, validateConversion as Re } from "./converters.js";
3
+ import { defaultClient as Ve, createNaviDataSource as Pe } from "./data-source.js";
4
+ import { strategies as je } from "./strategies.js";
5
+ import { indexRegistryStrategies as Me, registryKeyString as S, normalizeCapRegistry as Te, MAINNET_CAP_REGISTRY as Qe, normalizeEnv as $e, assertRegistryUsable as ve, accountCapType as he, registerCreatedCapPTB as Fe } from "./cap-registry.js";
6
+ import { validateAction as be, plan as Be, chooseConversion as Ke, metrics as Y } from "./planner.js";
7
+ import { positionSides as re, atomPrices as Ge, isDustClose as Q, tokenDecimals as D, leverageLimit as Ae, amountCushion as _e, withinLtv as ze, supplyCapacity as qe, borrowCapacity as Ye, withinSameReserveCapacity as He } from "./amounts.js";
8
+ import { check as o, jsonCopy as V, coinType as $, sameCoin as k, address as A, uint as H, BN as y, checksum as P, assertAddressPTB as Xe, minOutputGuard as ce } from "./utils.js";
9
+ import { validateFunding as We } from "./funding.js";
10
+ function rt(T = {}) {
11
+ const F = T.client ?? Ve(), X = T.converters ?? [Ue({ client: F }), Le({ client: F })], W = T.fallbackConverter ?? De({ services: T.services, client: F }), B = /* @__PURE__ */ new Map();
12
+ for (const e of [...X, W])
13
+ o(!B.has(e.id), "INVALID_ARGUMENT", `Duplicate converter id: ${e.id}`), B.set(e.id, e);
14
+ const j = (T.strategies ?? Object.values(je)).map(
15
+ (e) => pe(V(e))
16
16
  );
17
17
  o(
18
18
  new Set(j.map((e) => e.id)).size === j.length,
19
19
  "INVALID_ARGUMENT",
20
20
  "Strategy registry contains duplicate ids"
21
21
  );
22
- const Y = Pe(j), ie = new Set((C.retiredRegistryKeys ?? []).map(N));
22
+ const J = Me(j), se = new Set((T.retiredRegistryKeys ?? []).map(S));
23
23
  o(
24
- [...ie].every((e) => !Y.has(e)),
24
+ [...se].every((e) => !J.has(e)),
25
25
  "INVALID_ARGUMENT",
26
26
  "Active and retired Registry keys overlap"
27
27
  );
28
- const V = ye(C.capRegistry ?? Me);
28
+ const M = Te(T.capRegistry ?? Qe);
29
29
  o(
30
- !(C.dataSource && C.env !== void 0),
30
+ !(T.dataSource && T.env !== void 0),
31
31
  "INVALID_ARGUMENT",
32
32
  "env cannot be combined with a custom dataSource; set env on the data source"
33
33
  );
34
- const b = C.dataSource ?? je({
35
- client: $,
36
- services: C.services,
37
- capRegistry: C.capRegistry === void 0 ? void 0 : V,
34
+ const h = T.dataSource ?? Pe({
35
+ client: F,
36
+ services: T.services,
37
+ capRegistry: T.capRegistry === void 0 ? void 0 : M,
38
38
  strategies: j,
39
- retiredRegistryKeys: C.retiredRegistryKeys,
39
+ retiredRegistryKeys: T.retiredRegistryKeys,
40
40
  // ST-18: passed through as given; the data source normalizes it (omitted stays omitted, ST-01).
41
- env: C.env
42
- }), S = Qe(b.env), ce = C.capRegistry !== void 0;
43
- function se(e = "INVALID_ARGUMENT") {
41
+ env: T.env
42
+ }), U = $e(h.env), le = T.capRegistry !== void 0;
43
+ function ue(e = "INVALID_ARGUMENT") {
44
44
  o(
45
- b.capRegistry && JSON.stringify(ye(b.capRegistry)) === JSON.stringify(V),
45
+ h.capRegistry && JSON.stringify(Te(h.capRegistry)) === JSON.stringify(M),
46
46
  e,
47
47
  "DataSource Registry deployment differs from the execution deployment"
48
48
  );
49
49
  }
50
- se();
51
- async function X(e, l = "INVALID_ARGUMENT") {
52
- const t = le(D(e)), g = Y.get(N(t.registryKey));
50
+ ue();
51
+ async function Z(e, l = "INVALID_ARGUMENT") {
52
+ const t = pe(V(e)), g = J.get(S(t.registryKey));
53
53
  return o(
54
- g && await R(g) === await R(t),
54
+ g && await P(g) === await P(t),
55
55
  l,
56
56
  "Strategy differs from the configured Registry binding"
57
57
  ), t;
58
58
  }
59
- function le(e) {
59
+ function pe(e) {
60
60
  o(
61
61
  typeof e?.id == "string" && /^[a-z0-9][a-z0-9_-]{0,63}$/.test(e.id),
62
62
  "INVALID_ARGUMENT",
@@ -69,19 +69,19 @@ function rt(C = {}) {
69
69
  e.emodeId === void 0 || Number.isSafeInteger(e.emodeId) && e.emodeId >= 0,
70
70
  "INVALID_ARGUMENT",
71
71
  "E-Mode ID must be a nonnegative safe integer"
72
- ), N(e.registryKey);
72
+ ), S(e.registryKey);
73
73
  const l = {
74
74
  ...e,
75
75
  registryKey: { ...e.registryKey },
76
- principalCoinType: Q(e.principalCoinType),
77
- collateralCoinType: Q(e.collateralCoinType),
78
- debtCoinType: Q(e.debtCoinType)
76
+ principalCoinType: $(e.principalCoinType),
77
+ collateralCoinType: $(e.collateralCoinType),
78
+ debtCoinType: $(e.debtCoinType)
79
79
  };
80
80
  return o(
81
81
  (k(l.principalCoinType, l.debtCoinType) || k(l.principalCoinType, l.collateralCoinType)) && !k(l.collateralCoinType, l.debtCoinType),
82
82
  "STRATEGY_UNSUPPORTED",
83
83
  "Principal must equal collateral or debt, with distinct collateral and debt"
84
- ), l.acceptedInputCoinTypes = (l.acceptedInputCoinTypes ?? [l.principalCoinType]).map(Q), o(
84
+ ), l.acceptedInputCoinTypes = (l.acceptedInputCoinTypes ?? [l.principalCoinType]).map($), o(
85
85
  l.acceptedInputCoinTypes.length > 0 && l.acceptedInputCoinTypes[0] === l.principalCoinType && new Set(l.acceptedInputCoinTypes).size === l.acceptedInputCoinTypes.length && l.acceptedInputCoinTypes.every(
86
86
  (t) => t === l.collateralCoinType || t === l.debtCoinType
87
87
  ),
@@ -89,20 +89,20 @@ function rt(C = {}) {
89
89
  "Accepted inputs must be distinct strategy assets with principal first"
90
90
  ), l;
91
91
  }
92
- async function H(e) {
93
- se("STALE_QUOTE");
94
- const l = await b.listAccountCaps(e), t = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
92
+ async function x(e) {
93
+ ue("STALE_QUOTE");
94
+ const l = await h.listAccountCaps(e), t = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
95
95
  return l.map((n) => {
96
- const d = N(n.registryKey), c = Y.get(d), i = _(n.id), A = _(n.accountOwner);
96
+ const d = S(n.registryKey), c = J.get(d), r = A(n.id), b = A(n.accountOwner);
97
97
  return o(
98
- i !== _("0x0") && A !== _("0x0"),
98
+ r !== A("0x0") && b !== A("0x0"),
99
99
  "INVALID_ACCOUNT_CAP",
100
100
  "Zero Cap identity"
101
101
  ), o(
102
- !t.has(d) && !g.has(i) && !a.has(A),
102
+ !t.has(d) && !g.has(r) && !a.has(b),
103
103
  "DUPLICATE_ACCOUNT_CAP",
104
104
  "Duplicate strategy, Cap or lending account in Registry"
105
- ), t.add(d), g.add(i), a.add(A), ie.has(d) ? null : (o(c, "UNSUPPORTED_REGISTRY_STRATEGY", "Unknown registered Multiply strategy"), o(
105
+ ), t.add(d), g.add(r), a.add(b), se.has(d) ? null : (o(c, "UNSUPPORTED_REGISTRY_STRATEGY", "Unknown registered Multiply strategy"), o(
106
106
  c.id === n.strategyId,
107
107
  "INVALID_ACCOUNT_CAP",
108
108
  "Cap numeric binding differs from strategy ID"
@@ -110,102 +110,111 @@ function rt(C = {}) {
110
110
  n.transient === void 0 || n.transient === !0,
111
111
  "INVALID_ACCOUNT_CAP",
112
112
  "Cap transient marker must be true or absent"
113
- ), { ...n, id: i, accountOwner: A, registryKey: { ...n.registryKey } });
113
+ ), { ...n, id: r, accountOwner: b, registryKey: { ...n.registryKey } });
114
114
  }).filter((n) => n !== null);
115
115
  }
116
- function W(e, l) {
117
- const t = N(l.registryKey);
118
- return e.find((g) => N(g.registryKey) === t);
116
+ function ee(e, l) {
117
+ const t = S(l.registryKey);
118
+ return e.find((g) => S(g.registryKey) === t);
119
119
  }
120
- async function _e(e, l = {}) {
121
- e = _(e);
122
- const t = [], g = await H(e);
120
+ async function Ie(e, l = {}) {
121
+ e = A(e);
122
+ const t = [], g = await x(e);
123
123
  for (const a of l.strategy ? [l.strategy] : j) {
124
- const n = await X(a), d = W(g, n);
124
+ const n = await Z(a), d = ee(g, n);
125
125
  if (!d) continue;
126
- const c = await b.readMarket(n), i = await b.readPosition(d, n, c);
127
- z(n, c), q(i.collateralAmount), q(i.debtAmount), t.push({
126
+ const c = await h.readMarket(n), r = await h.readPosition(d, n, c);
127
+ q(n, c), H(r.collateralAmount), H(r.debtAmount), t.push({
128
128
  address: e,
129
129
  strategy: n,
130
130
  accountCap: d,
131
- ...i,
132
- ...ve(i, c)
131
+ ...r,
132
+ ...Y(r, c)
133
133
  });
134
134
  }
135
135
  return t;
136
136
  }
137
- async function he(e, l, t, g) {
138
- e = _(e), o(e !== _("0x0"), "INVALID_ARGUMENT", "Multiply owner cannot be zero"), Te(t, g);
139
- const a = await X(l);
137
+ async function we(e, l, t, g) {
138
+ e = A(e), o(e !== A("0x0"), "INVALID_ARGUMENT", "Multiply owner cannot be zero"), be(t, g);
139
+ const a = await Z(l);
140
140
  if (t.type === "open" || t.type === "add_principal") {
141
- const r = Q(t.inputCoinType ?? a.principalCoinType);
141
+ const m = $(t.inputCoinType ?? a.principalCoinType);
142
142
  o(
143
- a.acceptedInputCoinTypes.includes(r),
143
+ a.acceptedInputCoinTypes.includes(m),
144
144
  "UNSUPPORTED_INPUT_COIN",
145
145
  "Input coin is not accepted by this strategy"
146
- ), t = { ...t, inputCoinType: r };
146
+ ), t = { ...t, inputCoinType: m };
147
147
  }
148
- const n = W(await H(e), a);
148
+ const n = ee(await x(e), a);
149
149
  o(
150
150
  n || t.type === "open",
151
151
  "POSITION_NOT_FOUND",
152
152
  "Only open may create a Multiply Cap"
153
153
  );
154
- const d = await b.readMarket(a);
155
- z(a, d);
156
- const c = n ? await b.readPosition(n, a, d) : { collateralAmount: "0", debtAmount: "0" };
157
- q(c.collateralAmount), q(c.debtAmount);
158
- const i = n ? ae(c, d) : { collateral: !1, debt: !1 }, A = !i.collateral && !i.debt;
154
+ const d = await h.readMarket(a);
155
+ q(a, d);
156
+ const c = n ? await h.readPosition(n, a, d) : { collateralAmount: "0", debtAmount: "0" };
157
+ H(c.collateralAmount), H(c.debtAmount);
158
+ const r = n ? re(c, d) : { collateral: !1, debt: !1 }, b = !r.collateral && !r.debt;
159
159
  if (o(
160
- t.type !== "open" || A,
160
+ t.type !== "open" || b,
161
161
  "POSITION_EXISTS",
162
162
  "Use add_principal or set_leverage for an existing position"
163
163
  ), o(
164
- t.type === "open" || !A,
164
+ t.type === "open" || !b,
165
165
  "POSITION_NOT_FOUND",
166
166
  "Empty position; use open to reuse this Cap"
167
167
  ), "targetLeverage" in t && t.targetLeverage) {
168
- const r = new m(d.liquidationThreshold).div(
169
- new m(d.borrowWeight).times(g.minHealthFactor)
170
- ), E = new m(1).minus(new m(1).div(t.targetLeverage)), I = Ke(d), O = !["open", "add_principal"].includes(t.type) && E.times(c.collateralAmount).times(I.collateral).lte(new m(c.debtAmount).times(I.debt));
168
+ const m = new y(d.liquidationThreshold).div(
169
+ new y(d.borrowWeight).times(g.minHealthFactor)
170
+ ), L = new y(1).minus(new y(1).div(t.targetLeverage)), N = Ge(d), te = !["open", "add_principal"].includes(t.type) && L.times(c.collateralAmount).times(N.collateral).lte(new y(c.debtAmount).times(N.debt));
171
171
  o(
172
- E.lte(r) && (E.lte(new m(d.ltv).div(d.borrowWeight)) || O),
172
+ L.lte(m) && (L.lte(new y(d.ltv).div(d.borrowWeight)) || te),
173
173
  "CONSTRAINT_VIOLATION",
174
174
  "Target leverage exceeds protocol or health factor limits"
175
175
  );
176
176
  }
177
- const u = await b.readBorrowFeeBps(d, n?.accountOwner), w = await Fe(
177
+ const u = await h.readBorrowFeeBps(d, n?.accountOwner), _ = { coinIn: a.debtCoinType, coinOut: a.collateralCoinType }, O = X.filter((m) => m.supports(_.coinIn, _.coinOut)), i = O.length === 0 ? W : O.length === 1 ? O[0] : void 0, I = await Be(
178
178
  a,
179
179
  t,
180
180
  g,
181
181
  c,
182
182
  d,
183
183
  u,
184
- (r) => Be(r, ne, re)
184
+ (m) => Ke(m, X, W),
185
+ i?.getRateHint ? () => i.getRateHint(_) : void 0,
186
+ i?.getStakingSnapshot ? async () => {
187
+ const m = await i.getStakingSnapshot(_);
188
+ return m && o(
189
+ m.converterId === i.id,
190
+ "INVALID_CONVERSION",
191
+ "Native snapshot provider mismatch"
192
+ ), m;
193
+ } : void 0
185
194
  );
186
- n || (fe(S, ce), Ce(S));
187
- const T = {
195
+ n || (ve(U, le), he(U));
196
+ const w = {
188
197
  address: e,
189
198
  strategy: a,
190
- action: D(t),
191
- constraints: D(g),
199
+ action: V(t),
200
+ constraints: V(g),
192
201
  expiresAt: Math.min(
193
202
  Date.now() + 12e4,
194
- ...w.execution.conversions.map((r) => r.expiresAt)
203
+ ...I.execution.conversions.map((m) => m.expiresAt)
195
204
  ),
196
- estimate: w.estimate,
205
+ estimate: I.estimate,
197
206
  execution: {
198
- ...w.execution,
199
- env: S,
200
- capRegistry: { ...V },
207
+ ...I.execution,
208
+ env: U,
209
+ capRegistry: { ...M },
201
210
  accountCap: n ? { kind: "existing", ...n } : { kind: "create", registryKey: { ...a.registryKey } },
202
211
  checksum: ""
203
212
  }
204
213
  };
205
- return T.execution.checksum = await R(T), D(T);
214
+ return w.execution.checksum = await P(w), V(w);
206
215
  }
207
- async function Ie(e, l) {
208
- const t = e.execution, g = e.strategy, a = W(await H(e.address), g);
216
+ async function Ee(e, l) {
217
+ const t = e.execution, g = e.strategy, a = ee(await x(e.address), g);
209
218
  t.accountCap.kind === "create" ? o(
210
219
  !a && !l.accountCap,
211
220
  "STALE_QUOTE",
@@ -214,10 +223,10 @@ function rt(C = {}) {
214
223
  a && a.id === t.accountCap.id && a.accountOwner === t.accountCap.accountOwner,
215
224
  "STALE_QUOTE",
216
225
  "AccountCap changed since quote"
217
- ), typeof l.accountCap == "string" && o(_(l.accountCap) === _(a.id), "INVALID_INPUTS", "Wrong AccountCap"));
218
- const n = await b.readMarket(g);
219
- z(g, n), me(e.action, e.execution, n);
220
- for (const T of [
226
+ ), typeof l.accountCap == "string" && o(A(l.accountCap) === A(a.id), "INVALID_INPUTS", "Wrong AccountCap"));
227
+ const n = await h.readMarket(g);
228
+ q(g, n), Ce(e.action, e.execution, n);
229
+ for (const i of [
221
230
  "package",
222
231
  "storage",
223
232
  "priceOracle",
@@ -225,94 +234,101 @@ function rt(C = {}) {
225
234
  "incentiveV3",
226
235
  "limter"
227
236
  ])
228
- o(n.config[T] === t.market.config[T], "STALE_QUOTE", `Market ${T} changed`);
237
+ o(n.config[i] === t.market.config[i], "STALE_QUOTE", `Market ${i} changed`);
229
238
  o(
230
- n.collateral.contract.pool === t.market.collateral.contract.pool && n.debt.contract.pool === t.market.debt.contract.pool && n.flash.poolId === t.market.flash.poolId && U(n.collateral) === U(t.market.collateral) && U(n.debt) === U(t.market.debt),
239
+ n.collateral.contract.pool === t.market.collateral.contract.pool && n.debt.contract.pool === t.market.debt.contract.pool && n.flash.poolId === t.market.flash.poolId && D(n.collateral) === D(t.market.collateral) && D(n.debt) === D(t.market.debt),
231
240
  "STALE_QUOTE",
232
241
  "Pool configuration changed"
233
242
  );
234
- const d = a ? await b.readPosition(a, g, n) : { collateralAmount: "0", debtAmount: "0" };
243
+ const d = a ? await h.readPosition(a, g, n) : { collateralAmount: "0", debtAmount: "0" };
235
244
  if (a) {
236
- const T = ae(d, n);
245
+ const i = re(d, n);
237
246
  if (o(
238
- e.action.type === "open" == (!T.collateral && !T.debt),
247
+ e.action.type === "open" == (!i.collateral && !i.debt),
239
248
  "STALE_QUOTE",
240
249
  "Position no longer satisfies the action"
241
250
  ), e.action.type !== "open") {
242
251
  o(
243
- t.snapshot.protocolCollateralAmount !== void 0 || U(n.collateral) >= 9 || t.snapshot.collateralAmount !== "0",
252
+ t.snapshot.protocolCollateralAmount !== void 0 || D(n.collateral) >= 9 || t.snapshot.collateralAmount !== "0",
244
253
  "STALE_QUOTE",
245
254
  "Quote lacks precise collateral state"
246
255
  );
247
- const r = ae(t.snapshot, n);
256
+ const I = re(t.snapshot, n);
248
257
  o(
249
- r.collateral === T.collateral && r.debt === T.debt,
258
+ I.collateral === i.collateral && I.debt === i.debt,
250
259
  "STALE_QUOTE",
251
260
  "Position crossed a zero balance"
252
261
  );
253
262
  }
254
- e.action.type === "close" && M(g, t.snapshot, n) && o(
255
- M(g, d, n),
263
+ e.action.type === "close" && Q(g, t.snapshot, n) && o(
264
+ Q(g, d, n),
256
265
  "STALE_QUOTE",
257
266
  "Collateral became transferable; request a new quote"
258
267
  );
259
268
  }
260
- const c = new m(d.collateralAmount).minus(t.snapshot.collateralAmount), i = new m(d.debtAmount).minus(t.snapshot.debtAmount);
269
+ const c = new y(d.collateralAmount).minus(t.snapshot.collateralAmount), r = new y(d.debtAmount).minus(t.snapshot.debtAmount);
261
270
  o(
262
271
  c.gte(0) && c.lte(
263
- new m(t.snapshot.collateralAmount).times("0.0001").plus(Ae(n.collateral))
264
- ) && i.gte(0) && i.lte(
265
- new m(t.snapshot.debtAmount).times("0.0001").plus(Ae(n.debt))
272
+ new y(t.snapshot.collateralAmount).times("0.0001").plus(_e(n.collateral))
273
+ ) && r.gte(0) && r.lte(
274
+ new y(t.snapshot.debtAmount).times("0.0001").plus(_e(n.debt))
266
275
  ),
267
276
  "STALE_QUOTE",
268
277
  "Position changed since quote"
269
278
  );
270
- const A = await b.readBorrowFeeBps(n, a?.accountOwner);
279
+ const b = await h.readBorrowFeeBps(n, a?.accountOwner);
271
280
  o(
272
- new m(t.borrowAmount).times(A).div(1e4).integerValue().lte(t.borrowFee),
281
+ new y(t.borrowAmount).times(b).div(1e4).integerValue().lte(t.borrowFee),
273
282
  "STALE_QUOTE",
274
283
  "Borrow fee increased"
275
284
  ), o(n.flash.feeBps === t.market.flash.feeBps, "STALE_QUOTE", "Flash fee changed");
276
285
  const u = {
277
- collateralAmount: new m(t.minCollateralAfter).plus(c).toFixed(0),
278
- debtAmount: new m(t.debtAfter).plus(e.action.type === "close" ? 0 : i).toFixed(0)
279
- }, w = ve(u, n);
280
- return o(
281
- w.healthFactor === null || new m(w.healthFactor).gte(e.constraints.minHealthFactor),
286
+ collateralAmount: new y(t.minCollateralAfter).plus(c).toFixed(0),
287
+ debtAmount: new y(t.debtAfter).plus(e.action.type === "close" ? 0 : r).toFixed(0)
288
+ }, _ = Y(u, n);
289
+ o(
290
+ _.healthFactor === null || new y(_.healthFactor).gte(e.constraints.minHealthFactor),
282
291
  "STALE_QUOTE",
283
292
  "Updated market no longer satisfies HF"
284
293
  ), o(
285
294
  Number.isSafeInteger(n.observedAt) && Date.now() - n.observedAt <= 12e4,
286
295
  "STALE_QUOTE",
287
296
  "Current market snapshot is stale"
288
- ), e.constraints.maxLeverage && w.leverage && o(
289
- new m(w.leverage).lte(be(e.constraints.maxLeverage)),
297
+ );
298
+ const O = Ae(
299
+ e.constraints.maxLeverage,
300
+ e.action,
301
+ t.direction,
302
+ Y(d, n).leverage
303
+ );
304
+ return O && _.leverage && o(
305
+ new y(_.leverage).lte(O),
290
306
  "STALE_QUOTE",
291
307
  "Updated market exceeds maximum leverage"
292
308
  ), o(
293
- Ge(u, d, n, t.direction !== "increase"),
309
+ ze(u, d, n, t.direction !== "increase"),
294
310
  "STALE_QUOTE",
295
311
  "Updated market exceeds LTV"
296
312
  ), o(
297
- new m(t.flashAmount).lte(n.flash.max) && (t.flashAmount === "0" || new m(t.flashAmount).gte(n.flash.min)),
313
+ new y(t.flashAmount).lte(n.flash.max) && (t.flashAmount === "0" || new y(t.flashAmount).gte(n.flash.min)),
298
314
  "CAPACITY_EXCEEDED",
299
315
  "Flash capacity changed"
300
316
  ), o(
301
- new m(t.collateralAfter).minus(t.snapshot.collateralAmount).lte(ze(n)),
317
+ new y(t.collateralAfter).minus(t.snapshot.collateralAmount).lte(qe(n)),
302
318
  "CAPACITY_EXCEEDED",
303
319
  "Supply capacity changed"
304
320
  ), o(
305
- new m(t.borrowAmount).plus(t.borrowFee).lte(qe(n)),
321
+ new y(t.borrowAmount).plus(t.borrowFee).lte(Ye(n)),
306
322
  "CAPACITY_EXCEEDED",
307
323
  "Borrow liquidity changed"
308
324
  ), o(
309
- Ye(g, t, n),
325
+ He(g, t, n),
310
326
  "CAPACITY_EXCEEDED",
311
327
  "Flash and borrow from the same reserve exceed its cash"
312
328
  ), { fresh: n, now: d };
313
329
  }
314
- async function ue(e, l, t, g) {
315
- const a = D(l);
330
+ async function de(e, l, t, g) {
331
+ const a = V(l);
316
332
  o(
317
333
  a.execution?.version === 4,
318
334
  "INVALID_QUOTE",
@@ -320,7 +336,7 @@ function rt(C = {}) {
320
336
  );
321
337
  const n = a.execution.checksum;
322
338
  a.execution.checksum = "", o(
323
- n === await R(a),
339
+ n === await P(a),
324
340
  "INVALID_QUOTE",
325
341
  "Quote contents have changed; request a fresh quote"
326
342
  ), a.execution.checksum = n, o(
@@ -328,52 +344,52 @@ function rt(C = {}) {
328
344
  "INVALID_QUOTE",
329
345
  "Quote has no NAVI env (made by an older SDK); request a fresh quote"
330
346
  ), o(
331
- a.execution.env === S,
347
+ a.execution.env === U,
332
348
  "INVALID_QUOTE",
333
- `Quote was made for NAVI env ${String(a.execution.env)}; this client targets ${S}`
349
+ `Quote was made for NAVI env ${String(a.execution.env)}; this client targets ${U}`
334
350
  ), o(
335
351
  Number.isSafeInteger(a.expiresAt) && a.expiresAt > Date.now(),
336
352
  "QUOTE_EXPIRED",
337
353
  "Multiply quote expired"
338
354
  ), o(
339
- _(a.address) !== _("0x0"),
355
+ A(a.address) !== A("0x0"),
340
356
  "INVALID_ARGUMENT",
341
357
  "Multiply owner cannot be zero"
342
- ), await X(a.strategy, "STALE_QUOTE"), o(
343
- await R(a.execution.capRegistry) === await R(V),
358
+ ), await Z(a.strategy, "STALE_QUOTE"), o(
359
+ await P(a.execution.capRegistry) === await P(M),
344
360
  "STALE_QUOTE",
345
361
  "Registry deployment changed since quote"
346
362
  ), o(
347
- N(a.execution.accountCap.registryKey) === N(a.strategy.registryKey),
363
+ S(a.execution.accountCap.registryKey) === S(a.strategy.registryKey),
348
364
  "INVALID_QUOTE",
349
365
  "Quote Cap key differs from strategy"
350
366
  );
351
367
  const d = e.getData().sender;
352
368
  o(
353
- !d || _(d) === _(a.address),
369
+ !d || A(d) === A(a.address),
354
370
  "INVALID_INPUTS",
355
371
  "Transaction sender differs from quote wallet"
356
- ), Te(a.action, a.constraints);
357
- const c = a.execution, i = a.strategy;
358
- He(a);
359
- const A = t.coins ?? [];
372
+ ), be(a.action, a.constraints);
373
+ const c = a.execution, r = a.strategy;
374
+ We(a);
375
+ const b = t.coins ?? [];
360
376
  o(
361
- A.length === a.estimate.inputs.length,
377
+ b.length === a.estimate.inputs.length,
362
378
  "INVALID_INPUTS",
363
379
  "Provide exactly the quoted input coins"
364
380
  );
365
381
  for (const s of a.estimate.inputs)
366
382
  o(
367
- A.filter((p) => k(p.coinType, s.coinType)).length === 1,
383
+ b.filter((p) => k(p.coinType, s.coinType)).length === 1,
368
384
  "INVALID_INPUTS",
369
385
  `Missing or duplicate input: ${s.coinType}`
370
386
  );
371
387
  for (const s of c.conversions)
372
388
  o(
373
- F.has(s.converterId),
389
+ B.has(s.converterId),
374
390
  "INVALID_CONVERSION",
375
391
  "Quoted converter is not configured"
376
- ), De(
392
+ ), Re(
377
393
  s,
378
394
  {
379
395
  coinIn: s.input.coinType,
@@ -383,69 +399,69 @@ function rt(C = {}) {
383
399
  },
384
400
  s.converterId
385
401
  );
386
- const { fresh: u, now: w } = g ? { fresh: c.market, now: c.snapshot } : await Ie(a, t);
387
- z(i, u), me(a.action, c, u), c.accountCap.kind === "create" && fe(S, ce);
388
- const T = c.accountCap.kind === "existing" && c.accountCap.transient === !0;
402
+ const { fresh: u, now: _ } = g ? { fresh: c.market, now: c.snapshot } : await Ee(a, t);
403
+ q(r, u), Ce(a.action, c, u), c.accountCap.kind === "create" && ve(U, le);
404
+ const O = c.accountCap.kind === "existing" && c.accountCap.transient === !0;
389
405
  o(
390
- !T || t.accountCap !== void 0,
406
+ !O || t.accountCap !== void 0,
391
407
  "INVALID_INPUTS",
392
408
  "A transient AccountCap must be supplied as a transaction argument"
393
- ), e.setSenderIfNotSet(a.address), await b.prepareOracle(e, i, u);
394
- const r = u.config, E = c.accountCap.kind === "create" ? e.moveCall({ target: `${r.package}::lending::create_account` }) : void 0, I = E ?? t.accountCap ?? e.object(c.accountCap.id);
395
- c.accountCap.kind === "existing" && t.accountCap !== void 0 && !T && Xe(
409
+ ), e.setSenderIfNotSet(a.address), await h.prepareOracle(e, r, u);
410
+ const i = u.config, I = c.accountCap.kind === "create" ? e.moveCall({ target: `${i.package}::lending::create_account` }) : void 0, w = I ?? t.accountCap ?? e.object(c.accountCap.id);
411
+ c.accountCap.kind === "existing" && t.accountCap !== void 0 && !O && Xe(
396
412
  e,
397
413
  e.moveCall({
398
- target: `${r.package}::account::account_owner`,
399
- arguments: [I]
414
+ target: `${i.package}::account::account_owner`,
415
+ arguments: [w]
400
416
  }),
401
417
  c.accountCap.accountOwner
402
- ), E && (i.emodeId !== void 0 && e.moveCall({
403
- target: `${r.package}::lending::enter_emode_with_account_cap`,
404
- arguments: [e.object(r.storage), e.pure.u64(i.emodeId), E]
405
- }), $e(e, E, i.registryKey, V, Ce(S)));
406
- const O = [], J = (s, p) => {
407
- const f = A.find((L) => k(L.coinType, s)), y = e.splitCoins(f.coin, [p])[0];
408
- return O.push(f), y;
409
- }, P = (s, p) => e.moveCall({
418
+ ), I && (r.emodeId !== void 0 && e.moveCall({
419
+ target: `${i.package}::lending::enter_emode_with_account_cap`,
420
+ arguments: [e.object(i.storage), e.pure.u64(r.emodeId), I]
421
+ }), Fe(e, I, r.registryKey, M, he(U)));
422
+ const m = [], L = (s, p) => {
423
+ const C = b.find((R) => k(R.coinType, s)), f = e.splitCoins(C.coin, [p])[0];
424
+ return m.push(C), f;
425
+ }, N = (s, p) => e.moveCall({
410
426
  target: "0x2::coin::from_balance",
411
427
  typeArguments: [p],
412
428
  arguments: [s]
413
- }), Oe = (s, p) => e.moveCall({ target: "0x2::coin::into_balance", typeArguments: [p], arguments: [s] }), Z = (s) => e.moveCall({
414
- target: `${r.package}::incentive_v3::deposit_with_account_cap`,
415
- typeArguments: [i.collateralCoinType],
429
+ }), te = (s, p) => e.moveCall({ target: "0x2::coin::into_balance", typeArguments: [p], arguments: [s] }), ae = (s) => e.moveCall({
430
+ target: `${i.package}::incentive_v3::deposit_with_account_cap`,
431
+ typeArguments: [r.collateralCoinType],
416
432
  arguments: [
417
433
  e.object("0x6"),
418
- e.object(r.storage),
434
+ e.object(i.storage),
419
435
  e.object(u.collateral.contract.pool),
420
436
  e.pure.u8(u.collateral.id),
421
437
  s,
422
- e.object(r.incentiveV2),
423
- e.object(r.incentiveV3),
424
- I
438
+ e.object(i.incentiveV2),
439
+ e.object(i.incentiveV3),
440
+ w
425
441
  ]
426
- }), pe = (s) => P(
442
+ }), ge = (s) => N(
427
443
  e.moveCall({
428
- target: `${r.package}::incentive_v3::repay_with_account_cap`,
429
- typeArguments: [i.debtCoinType],
444
+ target: `${i.package}::incentive_v3::repay_with_account_cap`,
445
+ typeArguments: [r.debtCoinType],
430
446
  arguments: [
431
447
  e.object("0x6"),
432
- e.object(r.priceOracle),
433
- e.object(r.storage),
448
+ e.object(i.priceOracle),
449
+ e.object(i.storage),
434
450
  e.object(u.debt.contract.pool),
435
451
  e.pure.u8(u.debt.id),
436
452
  s,
437
- e.object(r.incentiveV2),
438
- e.object(r.incentiveV3),
439
- I
453
+ e.object(i.incentiveV2),
454
+ e.object(i.incentiveV3),
455
+ w
440
456
  ]
441
457
  }),
442
- i.debtCoinType
458
+ r.debtCoinType
443
459
  );
444
- let B, K;
460
+ let K, G;
445
461
  if (c.flashAmount !== "0") {
446
462
  const s = e.moveCall({
447
463
  target: `${u.flash.config.package}::lending::flash_loan_with_ctx_v2`,
448
- typeArguments: [i.debtCoinType],
464
+ typeArguments: [r.debtCoinType],
449
465
  arguments: [
450
466
  e.object(u.flash.config.flashloanConfig),
451
467
  e.object(u.flash.poolId),
@@ -453,87 +469,87 @@ function rt(C = {}) {
453
469
  e.object("0x5")
454
470
  ]
455
471
  });
456
- B = P(s[0], i.debtCoinType), K = s[1];
472
+ K = N(s[0], r.debtCoinType), G = s[1];
457
473
  }
458
- const de = (s) => K ? P(
474
+ const me = (s) => G ? N(
459
475
  e.moveCall({
460
476
  target: `${u.flash.config.package}::lending::flash_repay_with_ctx`,
461
- typeArguments: [i.debtCoinType],
477
+ typeArguments: [r.debtCoinType],
462
478
  arguments: [
463
479
  e.object("0x6"),
464
480
  e.object(u.flash.config.storage),
465
481
  e.object(u.flash.poolId),
466
- K,
467
- Oe(s, i.debtCoinType)
482
+ G,
483
+ te(s, r.debtCoinType)
468
484
  ]
469
485
  }),
470
- i.debtCoinType
471
- ) : s, ge = async (s, p) => {
472
- const f = await F.get(p.converterId).buildPTB(e, p, s, {
486
+ r.debtCoinType
487
+ ) : s, ye = async (s, p) => {
488
+ const C = await B.get(p.converterId).buildPTB(e, p, s, {
473
489
  changeRecipient: a.address
474
490
  });
475
- return oe(e, f.coinOut, p.minOutput.amount), O.push(...f.change), f.coinOut;
491
+ return ce(e, C.coinOut, p.minOutput.amount), m.push(...C.change), C.coinOut;
476
492
  };
477
493
  if (c.direction === "repay")
478
- O.push({
479
- coinType: i.debtCoinType,
480
- coin: pe(J(i.debtCoinType, a.estimate.inputs[0].amount))
494
+ m.push({
495
+ coinType: r.debtCoinType,
496
+ coin: ge(L(r.debtCoinType, a.estimate.inputs[0].amount))
481
497
  });
482
498
  else if (c.direction === "add_collateral")
483
- Z(J(i.collateralCoinType, a.estimate.inputs[0].amount));
499
+ ae(L(r.collateralCoinType, a.estimate.inputs[0].amount));
484
500
  else if (c.direction === "increase") {
485
- let s = B;
501
+ let s = K;
486
502
  if (c.funding.kind !== "none") {
487
- const p = J(c.funding.input.coinType, c.funding.input.amount);
488
- c.funding.kind === "collateral" ? Z(p) : s ? e.mergeCoins(s, [p]) : s = p;
503
+ const p = L(c.funding.input.coinType, c.funding.input.amount);
504
+ c.funding.kind === "collateral" ? ae(p) : s ? e.mergeCoins(s, [p]) : s = p;
489
505
  }
490
506
  for (const p of c.conversions)
491
- o(s, "INVALID_QUOTE", "Missing conversion funding"), Z(await ge(s, p)), s = void 0;
492
- if (K) {
507
+ o(s, "INVALID_QUOTE", "Missing conversion funding"), ae(await ye(s, p)), s = void 0;
508
+ if (G) {
493
509
  const p = e.moveCall({
494
- target: `${r.package}::incentive_v3::borrow_with_account_cap_v2`,
495
- typeArguments: [i.debtCoinType],
510
+ target: `${i.package}::incentive_v3::borrow_with_account_cap_v2`,
511
+ typeArguments: [r.debtCoinType],
496
512
  arguments: [
497
513
  e.object("0x6"),
498
- e.object(r.priceOracle),
499
- e.object(r.storage),
514
+ e.object(i.priceOracle),
515
+ e.object(i.storage),
500
516
  e.object(u.debt.contract.pool),
501
517
  e.pure.u8(u.debt.id),
502
518
  e.pure.u64(c.borrowAmount),
503
- e.object(r.incentiveV2),
504
- e.object(r.incentiveV3),
505
- I,
519
+ e.object(i.incentiveV2),
520
+ e.object(i.incentiveV3),
521
+ w,
506
522
  e.object("0x5")
507
523
  ]
508
524
  });
509
- O.push({ coinType: i.debtCoinType, coin: de(P(p, i.debtCoinType)) });
525
+ m.push({ coinType: r.debtCoinType, coin: me(N(p, r.debtCoinType)) });
510
526
  }
511
527
  } else {
512
- const s = B ? pe(B) : void 0;
528
+ const s = K ? ge(K) : void 0;
513
529
  let p = e.pure.u64(
514
530
  c.withdrawAmount
515
531
  );
516
532
  if (a.action.type === "close") {
517
533
  const v = e.moveCall({
518
- target: `${r.package}::account::account_owner`,
519
- arguments: [I]
534
+ target: `${i.package}::account::account_owner`,
535
+ arguments: [w]
520
536
  });
521
537
  e.moveCall({
522
- target: `${r.package}::lending::update_state_of_user`,
523
- arguments: [e.object("0x6"), e.object(r.storage), v]
538
+ target: `${i.package}::lending::update_state_of_user`,
539
+ arguments: [e.object("0x6"), e.object(i.storage), v]
524
540
  });
525
- const h = e.moveCall({
526
- target: `${r.package}::logic::user_collateral_balance`,
527
- arguments: [e.object(r.storage), e.pure.u8(u.collateral.id), v]
541
+ const E = e.moveCall({
542
+ target: `${i.package}::logic::user_collateral_balance`,
543
+ arguments: [e.object(i.storage), e.pure.u8(u.collateral.id), v]
528
544
  });
529
- if (M(i, c.snapshot, u))
530
- for (const [te, Ne] of [
531
- [h, e.pure.u256("1")],
532
- [e.pure.u256("999"), h]
545
+ if (Q(r, c.snapshot, u))
546
+ for (const [ie, Se] of [
547
+ [E, e.pure.u256("1")],
548
+ [e.pure.u256("999"), E]
533
549
  ]) {
534
550
  const ke = e.moveCall({
535
551
  target: "0x1::u256::checked_sub",
536
- arguments: [te, Ne]
552
+ arguments: [ie, Se]
537
553
  });
538
554
  e.moveCall({
539
555
  target: "0x1::option::destroy_some",
@@ -541,137 +557,143 @@ function rt(C = {}) {
541
557
  arguments: [ke]
542
558
  });
543
559
  }
544
- const ee = e.moveCall({ target: "0x1::u256::try_as_u64", arguments: [h] });
560
+ const ne = e.moveCall({ target: "0x1::u256::try_as_u64", arguments: [E] });
545
561
  if (p = e.moveCall({
546
562
  target: "0x1::option::destroy_some",
547
563
  typeArguments: ["u64"],
548
- arguments: [ee]
549
- }), U(u.collateral) !== 9 && (p = e.moveCall({
550
- target: `${r.package}::pool::unnormal_amount`,
551
- typeArguments: [i.collateralCoinType],
564
+ arguments: [ne]
565
+ }), D(u.collateral) !== 9 && (p = e.moveCall({
566
+ target: `${i.package}::pool::unnormal_amount`,
567
+ typeArguments: [r.collateralCoinType],
552
568
  arguments: [e.object(u.collateral.contract.pool), p]
553
- }), U(u.collateral) < 9)) {
554
- const te = e.moveCall({
569
+ }), D(u.collateral) < 9)) {
570
+ const ie = e.moveCall({
555
571
  target: "0x1::u64::checked_add",
556
572
  arguments: [p, e.pure.u64("1")]
557
573
  });
558
574
  p = e.moveCall({
559
575
  target: "0x1::option::destroy_some",
560
576
  typeArguments: ["u64"],
561
- arguments: [te]
577
+ arguments: [ie]
562
578
  });
563
579
  }
564
580
  }
565
- const f = P(
581
+ const C = N(
566
582
  e.moveCall({
567
- target: `${r.package}::incentive_v3::withdraw_with_account_cap_v2`,
568
- typeArguments: [i.collateralCoinType],
583
+ target: `${i.package}::incentive_v3::withdraw_with_account_cap_v2`,
584
+ typeArguments: [r.collateralCoinType],
569
585
  arguments: [
570
586
  e.object("0x6"),
571
- e.object(r.priceOracle),
572
- e.object(r.storage),
587
+ e.object(i.priceOracle),
588
+ e.object(i.storage),
573
589
  e.object(u.collateral.contract.pool),
574
590
  e.pure.u8(u.collateral.id),
575
591
  p,
576
- e.object(r.incentiveV2),
577
- e.object(r.incentiveV3),
578
- I,
592
+ e.object(i.incentiveV2),
593
+ e.object(i.incentiveV3),
594
+ w,
579
595
  e.object("0x5")
580
596
  ]
581
597
  }),
582
- i.collateralCoinType
598
+ r.collateralCoinType
583
599
  );
584
- let y;
600
+ let f;
585
601
  for (const v of c.conversions) {
586
- const h = e.splitCoins(f, [v.input.amount])[0];
587
- y = await ge(h, v);
602
+ const E = e.splitCoins(C, [v.input.amount])[0];
603
+ f = await ye(E, v);
588
604
  }
589
- s && (y ? e.mergeCoins(y, [s]) : y = s), y && (y = de(y));
590
- const L = k(i.principalCoinType, i.collateralCoinType) ? f : y, G = a.action.type === "close" && M(i, w, u) && M(i, c.snapshot, u);
591
- G || (o(L, "INVALID_QUOTE", "Missing principal output"), a.action.type === "remove_principal" && oe(e, L, a.action.amount));
605
+ s && (f ? e.mergeCoins(f, [s]) : f = s), f && (f = me(f));
606
+ const R = k(r.principalCoinType, r.collateralCoinType) ? C : f, z = a.action.type === "close" && Q(r, _, u) && Q(r, c.snapshot, u);
607
+ z || (o(R, "INVALID_QUOTE", "Missing principal output"), a.action.type === "remove_principal" && ce(e, R, a.action.amount));
592
608
  for (const v of a.estimate.minOutputs) {
593
- if (G && v.amount === "0" && k(v.coinType, i.principalCoinType))
609
+ if (z && v.amount === "0" && k(v.coinType, r.principalCoinType))
594
610
  continue;
595
- const h = k(v.coinType, i.collateralCoinType) ? f : y;
596
- o(h, "INVALID_QUOTE", "Missing minimum output coin"), oe(e, h, v.amount);
611
+ const E = k(v.coinType, r.collateralCoinType) ? C : f;
612
+ o(E, "INVALID_QUOTE", "Missing minimum output coin"), ce(e, E, v.amount);
597
613
  }
598
- O.push({ coinType: i.collateralCoinType, coin: f }), y && O.push({ coinType: i.debtCoinType, coin: y });
614
+ m.push({ coinType: r.collateralCoinType, coin: C }), f && m.push({ coinType: r.debtCoinType, coin: f });
599
615
  }
600
- const x = e.moveCall({
601
- target: `${r.package}::account::account_owner`,
602
- arguments: [I]
616
+ const oe = e.moveCall({
617
+ target: `${i.package}::account::account_owner`,
618
+ arguments: [w]
603
619
  });
604
620
  if (a.action.type === "close")
605
621
  for (const [s, p] of [
606
622
  ["user_collateral_balance", u.collateral.id],
607
623
  ["user_loan_balance", u.debt.id]
608
624
  ]) {
609
- const f = e.moveCall({
610
- target: `${r.package}::logic::${s}`,
611
- arguments: [e.object(r.storage), e.pure.u8(p), x]
612
- }), y = e.moveCall({
625
+ const C = e.moveCall({
626
+ target: `${i.package}::logic::${s}`,
627
+ arguments: [e.object(i.storage), e.pure.u8(p), oe]
628
+ }), f = e.moveCall({
613
629
  target: "0x1::u256::checked_sub",
614
- arguments: [e.pure.u256("0"), f]
630
+ arguments: [e.pure.u256("0"), C]
615
631
  });
616
632
  e.moveCall({
617
633
  target: "0x1::option::destroy_some",
618
634
  typeArguments: ["u256"],
619
- arguments: [y]
635
+ arguments: [f]
620
636
  });
621
637
  }
622
- if (a.constraints.maxLeverage !== void 0) {
623
- const s = (v, h) => e.moveCall({
624
- target: `${r.package}::logic::${v}`,
638
+ const fe = Ae(
639
+ a.constraints.maxLeverage,
640
+ a.action,
641
+ c.direction,
642
+ Y(_, u).leverage
643
+ );
644
+ if (fe) {
645
+ const s = (v, E) => e.moveCall({
646
+ target: `${i.package}::logic::${v}`,
625
647
  arguments: [
626
648
  e.object("0x6"),
627
- e.object(r.priceOracle),
628
- e.object(r.storage),
629
- e.pure.u8(h),
630
- x
649
+ e.object(i.priceOracle),
650
+ e.object(i.storage),
651
+ e.pure.u8(E),
652
+ oe
631
653
  ]
632
- }), p = (v, h) => {
633
- const ee = e.moveCall({
654
+ }), p = (v, E) => {
655
+ const ne = e.moveCall({
634
656
  target: "0x1::u256::checked_mul",
635
- arguments: [v, e.pure.u256(h)]
657
+ arguments: [v, e.pure.u256(E)]
636
658
  });
637
659
  return e.moveCall({
638
660
  target: "0x1::option::destroy_some",
639
661
  typeArguments: ["u256"],
640
- arguments: [ee]
662
+ arguments: [ne]
641
663
  });
642
- }, f = be(a.constraints.maxLeverage).shiftedBy(12).integerValue(m.ROUND_FLOOR), y = p(
664
+ }, C = fe.shiftedBy(12).integerValue(y.ROUND_FLOOR), f = p(
643
665
  s("user_collateral_value", u.collateral.id),
644
- f.minus("1e12").toFixed(0)
645
- ), L = p(s("user_loan_value", u.debt.id), f.toFixed(0)), G = e.moveCall({
666
+ C.minus("1e12").toFixed(0)
667
+ ), R = p(s("user_loan_value", u.debt.id), C.toFixed(0)), z = e.moveCall({
646
668
  target: "0x1::u256::checked_sub",
647
- arguments: [y, L]
669
+ arguments: [f, R]
648
670
  });
649
671
  e.moveCall({
650
672
  target: "0x1::option::destroy_some",
651
673
  typeArguments: ["u256"],
652
- arguments: [G]
674
+ arguments: [z]
653
675
  });
654
676
  }
655
677
  return e.moveCall({
656
- target: `${r.limter}::navi_adaptor::verify_navi_position_healthy`,
678
+ target: `${i.limter}::navi_adaptor::verify_navi_position_healthy`,
657
679
  arguments: [
658
680
  e.object("0x6"),
659
- e.object(r.storage),
660
- e.object(r.priceOracle),
661
- x,
681
+ e.object(i.storage),
682
+ e.object(i.priceOracle),
683
+ oe,
662
684
  e.pure.u256(
663
- new m(a.constraints.minHealthFactor).shiftedBy(27).integerValue(m.ROUND_CEIL).toFixed(0)
685
+ new y(a.constraints.minHealthFactor).shiftedBy(27).integerValue(y.ROUND_CEIL).toFixed(0)
664
686
  )
665
687
  ]
666
- }), { coins: O, accountCap: I, createdAccountCap: E };
688
+ }), { coins: m, accountCap: w, createdAccountCap: I };
667
689
  }
668
- function we(e, l, t) {
669
- return ue(e, l, t, !1);
690
+ function Oe(e, l, t) {
691
+ return de(e, l, t, !1);
670
692
  }
671
- function Ee(e, l, t) {
672
- return ue(e, l, { coins: t }, !0);
693
+ function Ne(e, l, t) {
694
+ return de(e, l, { coins: t }, !0);
673
695
  }
674
- return { getPosition: _e, quote: he, buildPTB: we, buildPTBForSimulation: Ee };
696
+ return { getPosition: Ie, quote: we, buildPTB: Oe, buildPTBForSimulation: Ne };
675
697
  }
676
698
  export {
677
699
  rt as createMultiplyClient