@naviprotocol/multiply 0.2.0-preview.20261102.1 → 0.2.0-preview.20261102.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/README.md CHANGED
@@ -40,6 +40,12 @@ tx.setSender(address)
40
40
 
41
41
  Actions: `open`, `add_principal`, `remove_principal`, `set_leverage`, `repay`,
42
42
  `add_collateral`, `close`. Amounts are **raw integer strings**, never JS numbers.
43
+ They use each token's native decimals (supported range: 0–18), including mixed-precision pairs. The
44
+ default data source converts NAVI's normalized nine-decimal balances into native
45
+ atoms (collateral down, debt up). `MarketSnapshot` prices are USD per whole token;
46
+ `Pool.availableBorrow` remains NAVI-normalized units and `Pool.leftSupply` remains
47
+ whole tokens. Injected data sources must follow the same contract. Frozen execution
48
+ plans now use version 2; version 1 quotes must be requested again before building.
43
49
  Leverage/HF use decimal strings; slippage uses integer basis points. An action
44
50
  with an `amount` requires a positive u64 value. `set_leverage` takes
45
51
  `targetLeverage`; add/remove principal optionally take it and otherwise preserve
@@ -60,6 +66,25 @@ slippage budget applies to that leg. Exact integer arithmetic is used throughout
60
66
 
61
67
  ## Converters and injection
62
68
 
69
+ Product strategy registration belongs to the calling application or API. Pass its
70
+ validated registry into the client; adding another supported token pair does not
71
+ require changing or publishing Multiply. The bundled `strategies` export remains
72
+ an optional compatibility preset, not a required allowlist.
73
+
74
+ ```ts
75
+ const multiply = createMultiplyClient({ strategies: apiOwnedStrategies })
76
+ // Discovery enumerates exactly this registry. quote() accepts a Strategy definition.
77
+ const positions = await multiply.getPosition(address)
78
+ ```
79
+
80
+ Registry IDs must be unique. The client snapshots the registry on initialization.
81
+ Strategies bind a stable ID, market and token types to an AccountCap. Keep mutable
82
+ names, display labels and product policies outside that definition. The supported
83
+ execution model remains one collateral token, a distinct debt token and principal
84
+ equal to debt, with lending v2, a health-factor limiter, main-market flash liquidity
85
+ and an immediate converter route. Unsupported capabilities fail explicitly; new
86
+ protocol mechanisms require an appropriate adapter rather than a new product ID.
87
+
63
88
  ```ts
64
89
  import {
65
90
  createMultiplyClient, createNaviDataSource, voloConverter, haedalConverter,
@@ -0,0 +1,19 @@
1
+ import { Pool } from '@naviprotocol/lending';
2
+ import { MarketSnapshot, PositionAmounts } from './types.js';
3
+
4
+ /** NAVI stores lending balances/capacity at 9 decimals, independently of Coin<T>. */
5
+ export declare const LENDING_DECIMALS = 9;
6
+ export declare function tokenDecimals(pool: Pick<Pool, 'token'>): number;
7
+ export declare function lendingToRaw(value: string, decimals: number, roundUp?: boolean): string;
8
+ /** Price of one native atom, used only inside the solver. Public prices stay USD/token. */
9
+ export declare function atomPrices(market: MarketSnapshot): {
10
+ collateral: import('bignumber.js').BigNumber;
11
+ debt: import('bignumber.js').BigNumber;
12
+ };
13
+ /** Existing one-micro-token interest/drift cushion, with at least one native atom. */
14
+ export declare function amountCushion(pool: Pick<Pool, 'token'>): import('bignumber.js').BigNumber;
15
+ export declare function supplyCapacity(market: MarketSnapshot): import('bignumber.js').BigNumber;
16
+ export declare function borrowCapacity(market: MarketSnapshot): import('bignumber.js').BigNumber;
17
+ /** A lowered borrowing cap must still permit repayment, collateral top-up and exit. */
18
+ export declare function withinLtv(projected: PositionAmounts, before: PositionAmounts, market: MarketSnapshot, allowReduction: boolean): boolean;
19
+ //# sourceMappingURL=amounts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"amounts.d.ts","sourceRoot":"","sources":["../src/amounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAG9D,qFAAqF;AACrF,eAAO,MAAM,gBAAgB,IAAI,CAAA;AAEjC,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,MAAM,CAQ/D;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,UAAQ,UAK5E;AAED,2FAA2F;AAC3F,wBAAgB,UAAU,CAAC,MAAM,EAAE,cAAc;;;EAKhD;AAED,sFAAsF;AACtF,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,oCAEtD;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,oCAOpD;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,oCAEpD;AAED,uFAAuF;AACvF,wBAAgB,SAAS,CACvB,SAAS,EAAE,eAAe,EAC1B,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,cAAc,EACtB,cAAc,EAAE,OAAO,WAiBxB"}
@@ -0,0 +1,46 @@
1
+ import { check as s, BN as e, decimal as r } from "./utils.js";
2
+ const m = 9;
3
+ function l(t) {
4
+ const n = t.token?.decimals;
5
+ return s(
6
+ Number.isInteger(n) && n >= 0 && n <= 18,
7
+ "MARKET_UNSUPPORTED",
8
+ "Token precision must be an integer from 0 to 18"
9
+ ), n;
10
+ }
11
+ function d(t, n, i = !1) {
12
+ return r(t).shiftedBy(n - m).integerValue(i ? e.ROUND_CEIL : e.ROUND_FLOOR).toFixed(0);
13
+ }
14
+ function f(t) {
15
+ return {
16
+ collateral: r(t.collateralPrice).shiftedBy(-l(t.collateral)),
17
+ debt: r(t.debtPrice).shiftedBy(-l(t.debt))
18
+ };
19
+ }
20
+ function w(t) {
21
+ return e.maximum(1, new e(1).shiftedBy(l(t) - 6));
22
+ }
23
+ function h(t) {
24
+ return e.maximum(
25
+ 0,
26
+ new e(t.collateral.leftSupply).shiftedBy(l(t.collateral)).integerValue(e.ROUND_FLOOR)
27
+ );
28
+ }
29
+ function p(t) {
30
+ return new e(d(t.debt.availableBorrow, l(t.debt)));
31
+ }
32
+ function y(t, n, i, a) {
33
+ const u = f(i), c = new e(t.collateralAmount), o = new e(t.debtAmount);
34
+ return o.times(u.debt).times(i.borrowWeight).lte(c.times(u.collateral).times(i.ltv)) ? !0 : a && o.lte(n.debtAmount) && o.times(n.collateralAmount).lte(new e(n.debtAmount).times(c));
35
+ }
36
+ export {
37
+ m as LENDING_DECIMALS,
38
+ w as amountCushion,
39
+ f as atomPrices,
40
+ p as borrowCapacity,
41
+ d as lendingToRaw,
42
+ h as supplyCapacity,
43
+ l as tokenDecimals,
44
+ y as withinLtv
45
+ };
46
+ //# sourceMappingURL=amounts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"amounts.js","sources":["../src/amounts.ts"],"sourcesContent":["import type { Pool } from '@naviprotocol/lending'\nimport type { MarketSnapshot, PositionAmounts } from './types'\nimport { BN, check, decimal } from './utils'\n\n/** NAVI stores lending balances/capacity at 9 decimals, independently of Coin<T>. */\nexport const LENDING_DECIMALS = 9\n\nexport function tokenDecimals(pool: Pick<Pool, 'token'>): number {\n const value = pool.token?.decimals\n check(\n Number.isInteger(value) && value >= 0 && value <= 18,\n 'MARKET_UNSUPPORTED',\n 'Token precision must be an integer from 0 to 18'\n )\n return value\n}\n\nexport function lendingToRaw(value: string, decimals: number, roundUp = false) {\n return decimal(value)\n .shiftedBy(decimals - LENDING_DECIMALS)\n .integerValue(roundUp ? BN.ROUND_CEIL : BN.ROUND_FLOOR)\n .toFixed(0)\n}\n\n/** Price of one native atom, used only inside the solver. Public prices stay USD/token. */\nexport function atomPrices(market: MarketSnapshot) {\n return {\n collateral: decimal(market.collateralPrice).shiftedBy(-tokenDecimals(market.collateral)),\n debt: decimal(market.debtPrice).shiftedBy(-tokenDecimals(market.debt))\n }\n}\n\n/** Existing one-micro-token interest/drift cushion, with at least one native atom. */\nexport function amountCushion(pool: Pick<Pool, 'token'>) {\n return BN.maximum(1, new BN(1).shiftedBy(tokenDecimals(pool) - 6))\n}\n\nexport function supplyCapacity(market: MarketSnapshot) {\n return BN.maximum(\n 0,\n new BN(market.collateral.leftSupply)\n .shiftedBy(tokenDecimals(market.collateral))\n .integerValue(BN.ROUND_FLOOR)\n )\n}\n\nexport function borrowCapacity(market: MarketSnapshot) {\n return new BN(lendingToRaw(market.debt.availableBorrow, tokenDecimals(market.debt)))\n}\n\n/** A lowered borrowing cap must still permit repayment, collateral top-up and exit. */\nexport function withinLtv(\n projected: PositionAmounts,\n before: PositionAmounts,\n market: MarketSnapshot,\n allowReduction: boolean\n) {\n const prices = atomPrices(market)\n const c = new BN(projected.collateralAmount),\n d = new BN(projected.debtAmount)\n if (\n d\n .times(prices.debt)\n .times(market.borrowWeight)\n .lte(c.times(prices.collateral).times(market.ltv))\n )\n return true\n return (\n allowReduction &&\n d.lte(before.debtAmount) &&\n d.times(before.collateralAmount).lte(new BN(before.debtAmount).times(c))\n )\n}\n"],"names":["LENDING_DECIMALS","tokenDecimals","pool","value","check","lendingToRaw","decimals","roundUp","decimal","BN","atomPrices","market","amountCushion","supplyCapacity","borrowCapacity","withinLtv","projected","before","allowReduction","prices","d"],"mappings":";AAKO,MAAMA,IAAmB;AAEzB,SAASC,EAAcC,GAAmC;AAC/D,QAAMC,IAAQD,EAAK,OAAO;AAC1B,SAAAE;AAAA,IACE,OAAO,UAAUD,CAAK,KAAKA,KAAS,KAAKA,KAAS;AAAA,IAClD;AAAA,IACA;AAAA,EAAA,GAEKA;AACT;AAEO,SAASE,EAAaF,GAAeG,GAAkBC,IAAU,IAAO;AAC7E,SAAOC,EAAQL,CAAK,EACjB,UAAUG,IAAWN,CAAgB,EACrC,aAAaO,IAAUE,EAAG,aAAaA,EAAG,WAAW,EACrD,QAAQ,CAAC;AACd;AAGO,SAASC,EAAWC,GAAwB;AACjD,SAAO;AAAA,IACL,YAAYH,EAAQG,EAAO,eAAe,EAAE,UAAU,CAACV,EAAcU,EAAO,UAAU,CAAC;AAAA,IACvF,MAAMH,EAAQG,EAAO,SAAS,EAAE,UAAU,CAACV,EAAcU,EAAO,IAAI,CAAC;AAAA,EAAA;AAEzE;AAGO,SAASC,EAAcV,GAA2B;AACvD,SAAOO,EAAG,QAAQ,GAAG,I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uBb,MAAM,oBACK,QAAQ,UAClB,MAAM,eACD,WAAW,KACvB,OAAO,CAAC,aAAa,CAAC;mBAoEnB,WAAW,iBACA,aAAa,UACpB,WAAW,KAClB,OAAO,CAAC,WAAW,CAAC;EA6axB"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkC,MAAM,0BAA0B,CAAA;AACtF,OAAO,KAAK,EAEV,MAAM,EACN,WAAW,EACX,WAAW,EACX,WAAW,EAGX,eAAe,EACf,aAAa,EACb,QAAQ,EACR,QAAQ,EACT,MAAM,SAAS,CAAA;AAyBhB,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,eAAoB;yBA4EvD,MAAM,UACN;QAAE,QAAQ,CAAC,EAAE,QAAQ,CAAA;KAAE,KAC7B,OAAO,CAAC,QAAQ,EAAE,CAAC;mBAuBb,MAAM,oBACK,QAAQ,UAClB,MAAM,eACD,WAAW,KACvB,OAAO,CAAC,aAAa,CAAC;mBAyEnB,WAAW,iBACA,aAAa,UACpB,WAAW,KAClB,OAAO,CAAC,WAAW,CAAC;EA0cxB"}