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

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.
@@ -1,295 +1,309 @@
1
- import { Transaction as U } from "@mysten/sui/transactions";
2
- import { bcs as m } from "@mysten/sui/bcs";
3
- import { SuiGrpcClient as Y } from "@mysten/sui/grpc";
4
- import { ReserveDataInfo as B, UserStateInfo as W, getConfig as K, getMarket as H, getAllFlashLoanAssets as J, updateOraclePricesPTB as Q } from "@naviprotocol/lending";
5
- import { jsonCopy as X, check as c, coinType as $, sameCoin as S, inspect as N, RAY as E, BN as y, address as P, MultiplyError as F, recordReadVersion as Z } from "./utils.js";
6
- import { lendingToRaw as G, tokenDecimals as x } from "./amounts.js";
7
- import { resolveEMode as ee } from "./emode.js";
8
- import { normalizeEnv as te, normalizeCapRegistry as re, MAINNET_CAP_REGISTRY as se, indexRegistryStrategies as ae, registryKeyString as q, assertRegistryUsable as ne, accountCapType as oe, decodeRegistryEntries as ie } from "./cap-registry.js";
9
- import { ACCOUNT_CAP_TYPE as ye } from "./cap-registry.js";
10
- import { strategies as ce } from "./strategies.js";
11
- const z = (g) => g.ratioOracleId !== void 0 && g.ratioOracleId !== null;
12
- function le(g, w) {
13
- const v = [];
1
+ import { marketOraclePrices as W } from "./market-prices.js";
2
+ import { Transaction as N } from "@mysten/sui/transactions";
3
+ import { bcs as u } from "@mysten/sui/bcs";
4
+ import { SuiGrpcClient as H } from "@mysten/sui/grpc";
5
+ import { ReserveDataInfo as K, UserStateInfo as J, getConfig as G, getMarket as Q, getAllFlashLoanAssets as X, updateOraclePricesPTB as Z } from "@naviprotocol/lending";
6
+ import { jsonCopy as ee, check as s, coinType as M, sameCoin as j, inspect as x, RAY as P, BN as h, address as k, MultiplyError as L, recordReadVersion as te } from "./utils.js";
7
+ import { lendingToRaw as q, tokenDecimals as S } from "./amounts.js";
8
+ import { resolveEMode as re } from "./emode.js";
9
+ import { normalizeEnv as ae, normalizeCapRegistry as se, MAINNET_CAP_REGISTRY as ne, indexRegistryStrategies as oe, registryKeyString as z, assertRegistryUsable as ie, accountCapType as ce, decodeRegistryEntries as le } from "./cap-registry.js";
10
+ import { ACCOUNT_CAP_TYPE as Ee } from "./cap-registry.js";
11
+ import { strategies as de } from "./strategies.js";
12
+ const Y = (n) => n.ratioOracleId !== void 0 && n.ratioOracleId !== null;
13
+ function ue(n, y) {
14
+ const b = [];
14
15
  for (const D of /* @__PURE__ */ new Set([
15
- $(w.collateralCoinType),
16
- $(w.debtCoinType)
16
+ M(y.collateralCoinType),
17
+ M(y.debtCoinType)
17
18
  ])) {
18
- const h = g.filter((b) => S(b.coinType, D)), T = h.filter((b) => !z(b)), R = h.filter(z);
19
- c(
20
- T.length === 1,
19
+ const T = n.filter((C) => j(C.coinType, D)), R = T.filter((C) => !Y(C)), E = T.filter(Y);
20
+ s(
21
+ R.length === 1,
21
22
  "MARKET_UNSUPPORTED",
22
- `Expected one own price feed for ${D}, found ${T.length}`
23
- ), c(
24
- R.length <= 1,
23
+ `Expected one own price feed for ${D}, found ${R.length}`
24
+ ), s(
25
+ E.length <= 1,
25
26
  "MARKET_UNSUPPORTED",
26
- `Expected at most one ratio feed for ${D}, found ${R.length}`
27
- ), v.push(T[0], ...R);
27
+ `Expected at most one ratio feed for ${D}, found ${E.length}`
28
+ ), b.push(R[0], ...E);
28
29
  }
29
- return v;
30
+ return b;
30
31
  }
31
- const de = () => new Y({ network: "mainnet", baseUrl: "https://fullnode.mainnet.sui.io:443" });
32
- function be(g = {}) {
33
- const w = te(g.env), v = g.client ?? de(), D = g.capRegistry !== void 0, h = re(g.capRegistry ?? se), T = ae(
34
- X(g.strategies ?? Object.values(ce))
35
- ), R = new Set((g.retiredRegistryKeys ?? []).map(q));
36
- c(
37
- [...R].every((e) => !T.has(e)),
32
+ const ge = () => new H({ network: "mainnet", baseUrl: "https://fullnode.mainnet.sui.io:443" });
33
+ function he(n = {}) {
34
+ const y = ae(n.env), b = n.client ?? ge(), D = n.capRegistry !== void 0, T = se(n.capRegistry ?? ne), R = oe(
35
+ ee(n.strategies ?? Object.values(de))
36
+ ), E = new Set((n.retiredRegistryKeys ?? []).map(z));
37
+ s(
38
+ [...E].every((a) => !R.has(a)),
38
39
  "INVALID_ARGUMENT",
39
40
  "Active and retired Registry keys overlap"
40
41
  );
41
- const b = g.measure ?? ((e, s) => s()), k = {
42
- services: g.services,
42
+ const C = n.measure ?? ((a, g) => g()), O = {
43
+ services: n.services,
43
44
  disableCache: !0,
44
- ...g.env === void 0 ? {} : { env: w }
45
+ ...n.env === void 0 ? {} : { env: y }
45
46
  };
46
- async function L(e, s, r) {
47
- const i = le(r.config.oracle.feeds, s);
48
- await Q(e, i, {
49
- ...k,
50
- market: s.market,
51
- client: v,
47
+ async function $(a, g, t) {
48
+ const o = ue(t.config.oracle.feeds, g);
49
+ await Z(a, o, {
50
+ ...O,
51
+ market: g.market,
52
+ client: b,
52
53
  updatePythPriceFeeds: !0
53
54
  });
54
55
  }
55
- const M = {
56
- prepareOracle: L,
57
- capRegistry: h,
58
- env: w,
59
- async listAccountCaps(e) {
60
- e = P(e), ne(w, D);
61
- const s = oe(w);
56
+ const B = {
57
+ marketPriceMode: n.marketPriceMode,
58
+ prepareOracle: $,
59
+ capRegistry: T,
60
+ env: y,
61
+ async listAccountCaps(a) {
62
+ a = k(a), ie(y, D);
63
+ const g = ce(y);
62
64
  try {
63
- const r = new U();
64
- r.setSender(e), r.moveCall({
65
- target: `${h.packageId}::multiply_registry::find_user_mul_account_caps`,
66
- arguments: [r.object(h.objectId), r.pure.address(e)]
65
+ const t = new N();
66
+ t.setSender(a), t.moveCall({
67
+ target: `${T.packageId}::multiply_registry::find_user_mul_account_caps`,
68
+ arguments: [t.object(T.objectId), t.pure.address(a)]
67
69
  });
68
- const i = g.onReadEvidence ? {} : void 0, f = await N(v, r, i), l = ie(f[0]?.returnValues);
69
- c(
70
- l.every((t) => t.capId !== P("0x0")),
70
+ const o = n.onReadEvidence ? {} : void 0, p = await x(b, t, o), c = le(p[0]?.returnValues);
71
+ s(
72
+ c.every((r) => r.capId !== k("0x0")),
71
73
  "INVALID_ACCOUNT_CAP",
72
74
  "Registry contains a zero Cap"
73
- ), c(
74
- new Set(l.map((t) => t.capId)).size === l.length,
75
+ ), s(
76
+ new Set(c.map((r) => r.capId)).size === c.length,
75
77
  "DUPLICATE_ACCOUNT_CAP",
76
78
  "One Cap is registered to multiple strategies"
77
79
  );
78
- const p = l.filter(
79
- (t) => !R.has(q(t.registryKey))
80
- ), C = p.map((t) => {
81
- const n = `${t.registryKey.strategyNumericId}:${t.registryKey.strategyVersion}`, o = T.get(n);
82
- return c(
83
- o,
80
+ const m = c.filter(
81
+ (r) => !E.has(z(r.registryKey))
82
+ ), f = m.map((r) => {
83
+ const e = `${r.registryKey.strategyNumericId}:${r.registryKey.strategyVersion}`, l = R.get(e);
84
+ return s(
85
+ l,
84
86
  "UNSUPPORTED_REGISTRY_STRATEGY",
85
- `Unknown Multiply Registry strategy: ${n}`
86
- ), c(
87
- t.capId !== P("0x0"),
87
+ `Unknown Multiply Registry strategy: ${e}`
88
+ ), s(
89
+ r.capId !== k("0x0"),
88
90
  "INVALID_ACCOUNT_CAP",
89
91
  "Registry contains a zero Cap"
90
- ), o;
92
+ ), l;
91
93
  });
92
- c(
93
- new Set(p.map((t) => t.capId)).size === p.length,
94
+ s(
95
+ new Set(m.map((r) => r.capId)).size === m.length,
94
96
  "DUPLICATE_ACCOUNT_CAP",
95
97
  "One Cap is registered to multiple strategies"
96
98
  );
97
- const A = /* @__PURE__ */ new Map();
98
- for (let t = 0; t < p.length; t += 50) {
99
- const n = p.slice(t, t + 50).map((d) => d.capId), o = await v.core.getObjects({
100
- objectIds: n,
99
+ const _ = /* @__PURE__ */ new Map();
100
+ for (let r = 0; r < m.length; r += 50) {
101
+ const e = m.slice(r, r + 50).map((d) => d.capId), l = await b.core.getObjects({
102
+ objectIds: e,
101
103
  include: { content: !0 }
102
104
  });
103
- c(
104
- o.objects.length === n.length,
105
+ s(
106
+ l.objects.length === e.length,
105
107
  "READ_FAILED",
106
108
  "Incomplete Cap object response"
107
109
  );
108
- for (const d of o.objects) {
109
- c(
110
+ for (const d of l.objects) {
111
+ s(
110
112
  !(d instanceof Error),
111
113
  "INVALID_ACCOUNT_CAP",
112
114
  "Registered Cap is unavailable"
113
115
  );
114
- const O = P(d.objectId);
115
- c(
116
- n.includes(O) && !A.has(O),
116
+ const w = k(d.objectId);
117
+ s(
118
+ e.includes(w) && !_.has(w),
117
119
  "READ_FAILED",
118
120
  "Unexpected or duplicate Cap response"
119
- ), A.set(O, d);
121
+ ), _.set(w, d);
120
122
  }
121
123
  }
122
- const I = /* @__PURE__ */ new Set(), u = m.struct("AccountCap", { id: m.Address, owner: m.Address }), a = p.map((t, n) => {
123
- const o = A.get(t.capId);
124
- c(
125
- o && $(o.type) === s,
124
+ const I = /* @__PURE__ */ new Set(), v = u.struct("AccountCap", { id: u.Address, owner: u.Address }), i = m.map((r, e) => {
125
+ const l = _.get(r.capId);
126
+ s(
127
+ l && M(l.type) === g,
126
128
  "INVALID_ACCOUNT_CAP",
127
129
  "Registry object is not an AccountCap"
128
- ), c(
129
- o.owner.$kind === "AddressOwner" && P(o.owner.AddressOwner) === e,
130
+ ), s(
131
+ l.owner.$kind === "AddressOwner" && k(l.owner.AddressOwner) === a,
130
132
  "INVALID_ACCOUNT_CAP",
131
133
  "Registered Cap is not owned by this wallet"
132
134
  );
133
135
  let d;
134
136
  try {
135
- d = u.parse(o.content);
137
+ d = v.parse(l.content);
136
138
  } catch {
137
- throw new F("INVALID_ACCOUNT_CAP", "Invalid AccountCap content");
139
+ throw new L("INVALID_ACCOUNT_CAP", "Invalid AccountCap content");
138
140
  }
139
- return c(
140
- d.id === t.capId && d.owner !== P("0x0"),
141
+ return s(
142
+ d.id === r.capId && d.owner !== k("0x0"),
141
143
  "INVALID_ACCOUNT_CAP",
142
144
  "Invalid AccountCap identity"
143
- ), c(
145
+ ), s(
144
146
  !I.has(d.owner),
145
147
  "DUPLICATE_ACCOUNT_CAP",
146
148
  "Multiple strategies share one lending account"
147
- ), I.add(d.owner), i && Z(i, t.capId, o.version), {
148
- id: t.capId,
149
+ ), I.add(d.owner), o && te(o, r.capId, l.version), {
150
+ id: r.capId,
149
151
  accountOwner: d.owner,
150
- strategyId: C[n].id,
151
- registryKey: { ...t.registryKey }
152
+ strategyId: f[e].id,
153
+ registryKey: { ...r.registryKey }
152
154
  };
153
155
  });
154
- return i && g.onReadEvidence?.("caps", i), a;
155
- } catch (r) {
156
- throw r instanceof F ? r : new F("READ_FAILED", "Unable to read complete Multiply Registry snapshot");
156
+ return o && n.onReadEvidence?.("caps", o), i;
157
+ } catch (t) {
158
+ throw t instanceof L ? t : new L("READ_FAILED", "Unable to read complete Multiply Registry snapshot");
157
159
  }
158
160
  },
159
- async readMarket(e) {
160
- const [s, r, i, f] = await Promise.all([
161
- b("market_config", () => K({ ...k, market: e.market })),
162
- b("market_pools", () => H(e.market, k)),
163
- b("flash_config", () => K({ ...k, market: "main" })),
164
- b("flash_assets", () => J({ ...k, market: "main" }))
165
- ]), l = r.pools, p = l.find((_) => S(_.suiCoinType, e.collateralCoinType)), C = l.find((_) => S(_.suiCoinType, e.debtCoinType)), A = f.find((_) => S(_.coinType, e.debtCoinType));
166
- c(
167
- p && C && A,
161
+ async readMarket(a, g = n.marketPriceMode ?? "live") {
162
+ const [t, o, p, c] = await Promise.all([
163
+ C("market_config", () => G({ ...O, market: a.market })),
164
+ C("market_pools", () => Q(a.market, O)),
165
+ C("flash_config", () => G({ ...O, market: "main" })),
166
+ C("flash_assets", () => X({ ...O, market: "main" }))
167
+ ]), m = o.pools, f = m.find((A) => j(A.suiCoinType, a.collateralCoinType)), _ = m.find((A) => j(A.suiCoinType, a.debtCoinType)), I = c.find((A) => j(A.coinType, a.debtCoinType));
168
+ s(
169
+ f && _ && I,
168
170
  "MARKET_UNSUPPORTED",
169
171
  "Missing collateral, debt or main-market flash liquidity"
170
- ), c(
171
- s.version === 2 && s.limter,
172
+ ), s(
173
+ t.version === 2 && t.limter,
172
174
  "MARKET_UNSUPPORTED",
173
175
  "Requires lending v2 and an on-chain HF limiter"
174
176
  );
175
- const I = await ee(v, e, s, r, p, C);
176
- x(p), x(C);
177
- const u = {
178
- config: s,
179
- ...I ? { emode: { id: I.emodeId, active: I.isActive } } : {},
180
- collateral: p,
181
- debt: C,
177
+ const v = await re(b, a, t, o, f, _);
178
+ S(f), S(_);
179
+ const i = {
180
+ config: t,
181
+ ...v ? { emode: { id: v.emodeId, active: v.isActive } } : {},
182
+ collateral: f,
183
+ debt: _,
182
184
  collateralPrice: "",
183
185
  debtPrice: "",
184
186
  ltv: "",
185
187
  liquidationThreshold: "",
186
188
  borrowWeight: "",
187
189
  flash: {
188
- config: i,
189
- poolId: A.poolId,
190
- max: A.max,
191
- min: A.min,
190
+ config: p,
191
+ poolId: I.poolId,
192
+ max: I.max,
193
+ min: I.min,
192
194
  feeBps: "0"
193
195
  },
194
196
  observedAt: Date.now()
195
- }, a = new U();
196
- await b("market_oracle", () => L(a, e, u));
197
- const t = [p, C].map((_) => {
198
- const V = a.getData().commands.length;
199
- return a.moveCall({
200
- target: `${s.package}::calculator::calculate_value`,
197
+ }, r = g === "live" ? void 0 : await C(
198
+ "market_price_validate",
199
+ async () => W(a, t, y, f, _)
200
+ );
201
+ s(
202
+ r || g !== "market-only",
203
+ "PRICE_DATA_UNAVAILABLE",
204
+ "Fresh market oracle prices are required"
205
+ ), r && Object.assign(i, r);
206
+ const e = new N();
207
+ r || await C("market_oracle", () => $(e, a, i));
208
+ const l = r ? [] : [f, _].map((A) => {
209
+ const F = e.getData().commands.length;
210
+ return e.moveCall({
211
+ target: `${t.package}::calculator::calculate_value`,
201
212
  arguments: [
202
- a.object("0x6"),
203
- a.object(s.priceOracle),
204
- a.pure.u256("1000000000000000000"),
205
- a.pure.u8(_.oracleId)
213
+ e.object("0x6"),
214
+ e.object(t.priceOracle),
215
+ e.pure.u256("1000000000000000000"),
216
+ e.pure.u8(A.oracleId)
206
217
  ]
207
- }), V;
208
- }), n = a.getData().commands.length;
209
- a.moveCall({
210
- target: `${s.uiGetter}::getter::get_reserve_data`,
211
- arguments: [a.object(s.storage)]
212
- }), a.moveCall({
213
- target: `${s.package}::storage::get_borrow_weight`,
214
- arguments: [a.object(s.storage), a.pure.u8(C.id)]
215
- }), a.moveCall({
216
- target: `${i.package}::flash_loan::get_asset`,
217
- typeArguments: [e.debtCoinType],
218
- arguments: [a.object(i.flashloanConfig)]
218
+ }), F;
219
+ }), d = e.getData().commands.length;
220
+ e.moveCall({
221
+ target: `${t.uiGetter}::getter::get_reserve_data`,
222
+ arguments: [e.object(t.storage)]
223
+ }), e.moveCall({
224
+ target: `${t.package}::storage::get_borrow_weight`,
225
+ arguments: [e.object(t.storage), e.pure.u8(_.id)]
226
+ }), e.moveCall({
227
+ target: `${p.package}::flash_loan::get_asset`,
228
+ typeArguments: [a.debtCoinType],
229
+ arguments: [e.object(p.flashloanConfig)]
219
230
  });
220
- const o = await b("market_inspect", () => N(v, a)), d = o[n + 2].returnValues;
221
- c(
222
- m.Address.parse(d[3].bcs) === A.poolId,
231
+ const w = await C(
232
+ r ? "market_risk_inspect" : "market_inspect",
233
+ () => x(b, e)
234
+ ), U = w[d + 2].returnValues;
235
+ s(
236
+ u.Address.parse(U[3].bcs) === I.poolId,
223
237
  "READ_FAILED",
224
238
  "Flash pool differs from live configuration"
225
- ), u.flash.feeBps = (BigInt(m.u64().parse(d[4].bcs)) + BigInt(m.u64().parse(d[5].bcs))).toString(), u.flash.max = m.u64().parse(d[6].bcs), u.flash.min = m.u64().parse(d[7].bcs), u.collateralPrice = new y(
226
- m.u256().parse(o[t[0]].returnValues[0].bcs)
227
- ).div("1e18").toFixed(), u.debtPrice = new y(m.u256().parse(o[t[1]].returnValues[0].bcs)).div("1e18").toFixed();
228
- const j = m.vector(B).parse(o[n].returnValues[0].bcs).find((_) => _.id === p.id);
229
- if (c(j, "READ_FAILED", "Missing collateral risk parameters"), u.ltv = new y(j.ltv).div(E.toString()).toFixed(), u.liquidationThreshold = new y(j.liquidation_threshold).div(E.toString()).toFixed(), I) {
230
- const _ = I.assets.find((V) => V.assetId === p.id);
231
- u.ltv = new y(_.ltv).toFixed(), u.liquidationThreshold = new y(_.lt).toFixed();
239
+ ), i.flash.feeBps = (BigInt(u.u64().parse(U[4].bcs)) + BigInt(u.u64().parse(U[5].bcs))).toString(), i.flash.max = u.u64().parse(U[6].bcs), i.flash.min = u.u64().parse(U[7].bcs), r || (i.collateralPrice = new h(
240
+ u.u256().parse(w[l[0]].returnValues[0].bcs)
241
+ ).div("1e18").toFixed(), i.debtPrice = new h(u.u256().parse(w[l[1]].returnValues[0].bcs)).div("1e18").toFixed());
242
+ const V = u.vector(K).parse(w[d].returnValues[0].bcs).find((A) => A.id === f.id);
243
+ if (s(V, "READ_FAILED", "Missing collateral risk parameters"), i.ltv = new h(V.ltv).div(P.toString()).toFixed(), i.liquidationThreshold = new h(V.liquidation_threshold).div(P.toString()).toFixed(), v) {
244
+ const A = v.assets.find((F) => F.assetId === f.id);
245
+ i.ltv = new h(A.ltv).toFixed(), i.liquidationThreshold = new h(A.lt).toFixed();
232
246
  }
233
- return u.borrowWeight = new y(m.u64().parse(o[n + 1].returnValues[0].bcs)).div(1e4).toFixed(), u.observedAt = Date.now(), u;
247
+ return i.borrowWeight = new h(u.u64().parse(w[d + 1].returnValues[0].bcs)).div(1e4).toFixed(), i.observedAt = Date.now(), i;
234
248
  },
235
- async readPosition(e, s, r) {
236
- const i = r ?? await M.readMarket(s), { config: f } = i, l = new U();
237
- l.moveCall({
238
- target: `${f.package}::lending::update_state_of_user`,
239
- arguments: [l.object("0x6"), l.object(f.storage), l.pure.address(e.accountOwner)]
240
- }), l.moveCall({
241
- target: `${f.uiGetter}::getter::get_reserve_data`,
242
- arguments: [l.object(f.storage)]
243
- }), l.moveCall({
244
- target: `${f.uiGetter}::getter_unchecked::get_user_state`,
245
- arguments: [l.object(f.storage), l.pure.address(e.accountOwner)]
249
+ async readPosition(a, g, t) {
250
+ const o = t ?? await B.readMarket(g), { config: p } = o, c = new N();
251
+ c.moveCall({
252
+ target: `${p.package}::lending::update_state_of_user`,
253
+ arguments: [c.object("0x6"), c.object(p.storage), c.pure.address(a.accountOwner)]
254
+ }), c.moveCall({
255
+ target: `${p.uiGetter}::getter::get_reserve_data`,
256
+ arguments: [c.object(p.storage)]
257
+ }), c.moveCall({
258
+ target: `${p.uiGetter}::getter_unchecked::get_user_state`,
259
+ arguments: [c.object(p.storage), c.pure.address(a.accountOwner)]
246
260
  });
247
- const p = g.onReadEvidence ? {} : void 0, C = await N(v, l, p), A = m.vector(B).parse(C[1].returnValues[0].bcs), I = m.vector(W).parse(C[2].returnValues[0].bcs);
248
- let u = "0", a = "0";
249
- for (const n of I) {
250
- c(
251
- (n.asset_id === i.collateral.id || BigInt(n.supply_balance) === 0n) && (n.asset_id === i.debt.id || BigInt(n.borrow_balance) === 0n),
261
+ const m = n.onReadEvidence ? {} : void 0, f = await x(b, c, m), _ = u.vector(K).parse(f[1].returnValues[0].bcs), I = u.vector(J).parse(f[2].returnValues[0].bcs);
262
+ let v = "0", i = "0";
263
+ for (const e of I) {
264
+ s(
265
+ (e.asset_id === o.collateral.id || BigInt(e.supply_balance) === 0n) && (e.asset_id === o.debt.id || BigInt(e.borrow_balance) === 0n),
252
266
  "POSITION_UNSUPPORTED",
253
267
  "Account contains assets outside this strategy"
254
268
  );
255
- const o = A.find((d) => d.id === n.asset_id);
256
- c(o, "READ_FAILED", "Position references an unknown reserve"), n.asset_id === i.collateral.id && (u = ((BigInt(n.supply_balance) * BigInt(o.supply_index) + E / 2n) / E).toString()), n.asset_id === i.debt.id && (a = ((BigInt(n.borrow_balance) * BigInt(o.borrow_index) + E / 2n) / E).toString());
269
+ const l = _.find((d) => d.id === e.asset_id);
270
+ s(l, "READ_FAILED", "Position references an unknown reserve"), e.asset_id === o.collateral.id && (v = ((BigInt(e.supply_balance) * BigInt(l.supply_index) + P / 2n) / P).toString()), e.asset_id === o.debt.id && (i = ((BigInt(e.borrow_balance) * BigInt(l.borrow_index) + P / 2n) / P).toString());
257
271
  }
258
- const t = {
259
- collateralAmount: G(u, x(i.collateral)),
260
- debtAmount: G(a, x(i.debt), !0),
261
- protocolCollateralAmount: u,
262
- protocolDebtAmount: a
272
+ const r = {
273
+ collateralAmount: q(v, S(o.collateral)),
274
+ debtAmount: q(i, S(o.debt), !0),
275
+ protocolCollateralAmount: v,
276
+ protocolDebtAmount: i
263
277
  };
264
- return p && g.onReadEvidence?.("position", p), t;
278
+ return m && n.onReadEvidence?.("position", m), r;
265
279
  },
266
- async readBorrowFeeBps(e, s) {
267
- const r = new U(), i = s ? r.pure.address(s) : r.moveCall({
268
- target: `${e.config.package}::account::account_owner`,
280
+ async readBorrowFeeBps(a, g) {
281
+ const t = new N(), o = g ? t.pure.address(g) : t.moveCall({
282
+ target: `${a.config.package}::account::account_owner`,
269
283
  arguments: [
270
- r.moveCall({ target: `${e.config.package}::lending::create_account` })
284
+ t.moveCall({ target: `${a.config.package}::lending::create_account` })
271
285
  ]
272
- }), f = r.getData().commands.length;
273
- r.moveCall({
274
- target: `${e.config.package}::incentive_v3::get_borrow_fee_v2`,
286
+ }), p = t.getData().commands.length;
287
+ t.moveCall({
288
+ target: `${a.config.package}::incentive_v3::get_borrow_fee_v2`,
275
289
  arguments: [
276
- r.object(e.config.incentiveV3),
277
- i,
278
- r.pure.u8(e.debt.id),
279
- r.pure.u64(1e4)
290
+ t.object(a.config.incentiveV3),
291
+ o,
292
+ t.pure.u8(a.debt.id),
293
+ t.pure.u64(1e4)
280
294
  ]
281
295
  });
282
- const l = await N(v, r);
283
- return m.u64().parse(l[f].returnValues[0].bcs);
296
+ const c = await x(b, t);
297
+ return u.u64().parse(c[p].returnValues[0].bcs);
284
298
  }
285
299
  };
286
- return M;
300
+ return B;
287
301
  }
288
302
  export {
289
- ye as ACCOUNT_CAP_TYPE,
290
- be as createNaviDataSource,
291
- de as defaultClient,
292
- z as isRatioFeed,
293
- le as selectStrategyFeeds
303
+ Ee as ACCOUNT_CAP_TYPE,
304
+ he as createNaviDataSource,
305
+ ge as defaultClient,
306
+ Y as isRatioFeed,
307
+ ue as selectStrategyFeeds
294
308
  };
295
309
  //# sourceMappingURL=data-source.js.map