@naviprotocol/multiply 0.0.0-stage → 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 +200 -2
- package/dist/amounts.d.ts +19 -0
- package/dist/amounts.d.ts.map +1 -0
- package/dist/amounts.js +46 -0
- package/dist/amounts.js.map +1 -0
- package/dist/client.d.ts +11 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +508 -0
- package/dist/client.js.map +1 -0
- package/dist/converters.d.ts +16 -0
- package/dist/converters.d.ts.map +1 -0
- package/dist/converters.js +233 -0
- package/dist/converters.js.map +1 -0
- package/dist/data-source.d.ts +11 -0
- package/dist/data-source.d.ts.map +1 -0
- package/dist/data-source.js +220 -0
- package/dist/data-source.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/planner.d.ts +28 -0
- package/dist/planner.d.ts.map +1 -0
- package/dist/planner.js +296 -0
- package/dist/planner.js.map +1 -0
- package/dist/strategies.d.ts +21 -0
- package/dist/strategies.d.ts.map +1 -0
- package/dist/strategies.js +25 -0
- package/dist/strategies.js.map +1 -0
- package/dist/types.d.ts +179 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +25 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +83 -0
- package/dist/utils.js.map +1 -0
- package/package.json +52 -4
package/README.md
CHANGED
|
@@ -1,3 +1,201 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @naviprotocol/multiply
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
AccountCap-based NAVI Multiply strategy engine for wallets, Auto Vault and Open API.
|
|
4
|
+
Default NAVI reads, native Volo/Haedal quotes and Astros fallback are included.
|
|
5
|
+
The package builds composable Sui PTBs. It never signs or broadcasts transactions.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { Transaction } from '@mysten/sui/transactions'
|
|
9
|
+
import { createMultiplyClient, strategies } from '@naviprotocol/multiply'
|
|
10
|
+
|
|
11
|
+
const multiply = createMultiplyClient()
|
|
12
|
+
const positions = await multiply.getPosition(address, {
|
|
13
|
+
strategy: strategies.vsuiSui, // omit to read all configured strategies
|
|
14
|
+
})
|
|
15
|
+
const quote = await multiply.quote(
|
|
16
|
+
address,
|
|
17
|
+
strategies.vsuiSui,
|
|
18
|
+
{ type: 'open', amount: '10000000000', targetLeverage: '2' },
|
|
19
|
+
{ minHealthFactor: '1.15', maxSlippageBps: 50, maxLeverage: '3' },
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
const tx = new Transaction()
|
|
23
|
+
const input = tx.splitCoins(tx.gas, ['10000000000'])[0]
|
|
24
|
+
const built = await multiply.buildPTB(tx, quote, {
|
|
25
|
+
coins: [{ coinType: strategies.vsuiSui.principalCoinType, coin: input }],
|
|
26
|
+
})
|
|
27
|
+
// Astros route change goes directly to address; the caller handles the remaining assets.
|
|
28
|
+
if (built.createdAccountCap) tx.transferObjects([built.createdAccountCap], address)
|
|
29
|
+
if (built.coins.length) tx.transferObjects(built.coins.map(c => c.coin), address)
|
|
30
|
+
tx.setSender(address)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Public API
|
|
34
|
+
|
|
35
|
+
| Method | Behavior |
|
|
36
|
+
| --- | --- |
|
|
37
|
+
| `getPosition(address, { strategy? })` | Always returns an array. Missing Cap → `[]`; existing empty Cap → zero position. Returns Cap, amounts, HF and leverage. |
|
|
38
|
+
| `quote(address, strategy, action, constraints)` | Resolves the Cap and reads the snapshot internally. Does not create chain objects. Produces a JSON-serializable estimate and a frozen, versioned execution plan. |
|
|
39
|
+
| `buildPTB(tx, quote, inputs)` | Rechecks Cap, market, fees, state drift and expiry, then appends commands. Returns Cap and every remaining Coin for the caller to use. |
|
|
40
|
+
|
|
41
|
+
Actions: `open`, `add_principal`, `remove_principal`, `set_leverage`, `repay`,
|
|
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.
|
|
49
|
+
Leverage/HF use decimal strings; slippage uses integer basis points. An action
|
|
50
|
+
with an `amount` requires a positive u64 value. `set_leverage` takes
|
|
51
|
+
`targetLeverage`; add/remove principal optionally take it and otherwise preserve
|
|
52
|
+
the current estimated leverage. `close` takes no amount.
|
|
53
|
+
|
|
54
|
+
`estimate.inputs` defines the required Coin types and amounts. Supply one Coin
|
|
55
|
+
per type; the builder splits only the quoted amount and returns its remainder.
|
|
56
|
+
Repay overpayment is returned. Removing principal guarantees **at least** the
|
|
57
|
+
requested output; any surplus also returns to the caller. `healthFactor: null`
|
|
58
|
+
means no debt; `leverage: null` means an empty position or non-positive equity; inspect the returned balances. These ratios use NAVI's
|
|
59
|
+
oracle valuation, which can differ from a token's market or redemption value.
|
|
60
|
+
|
|
61
|
+
`execution` is opaque to callers. Do not modify it, reroute during build or cache
|
|
62
|
+
it beyond `expiresAt`. Min outputs include conversion wear/fees before slippage.
|
|
63
|
+
The solver recomputes leverage with conversion quotes, flash fees and NAVI borrow
|
|
64
|
+
fees. One atomic conversion leg is used per initial-release plan, so the total
|
|
65
|
+
slippage budget applies to that leg. Exact integer arithmetic is used throughout.
|
|
66
|
+
|
|
67
|
+
## Converters and injection
|
|
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
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import {
|
|
90
|
+
createMultiplyClient, createNaviDataSource, voloConverter, haedalConverter,
|
|
91
|
+
} from '@naviprotocol/multiply'
|
|
92
|
+
|
|
93
|
+
const multiply = createMultiplyClient({
|
|
94
|
+
client,
|
|
95
|
+
dataSource: createNaviDataSource({ client }), // optional, or your DataSource
|
|
96
|
+
converters: [voloConverter({ client }), haedalConverter({ client })],
|
|
97
|
+
// fallbackConverter: customConverter, // optional; default is Astros
|
|
98
|
+
})
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
A strategy describes tokens and lending market, not a converter. Eligible primary
|
|
102
|
+
converters are compared by minimum net output, then stable ID. If none can quote,
|
|
103
|
+
the fallback is used. A malformed primary quote fails instead of becoming a
|
|
104
|
+
silently accepted route. Volo uses its live `get_amount_out` view; Haedal uses
|
|
105
|
+
live conversion views and configured fees. Only immediate Coin → Coin conversion
|
|
106
|
+
is supported. Native instant redemption can become unavailable; requesting a new
|
|
107
|
+
quote can select the fallback. A build never silently selects another route.
|
|
108
|
+
|
|
109
|
+
Astros uses the published `@naviprotocol/astros-aggregator-sdk@2.0.7` with its default
|
|
110
|
+
fee and positive-slippage behavior. Route change is transferred directly to the
|
|
111
|
+
user in `quote.address`, independently of the transaction sender or gas sponsor.
|
|
112
|
+
It is not included in `built.coins`. The engine's other remaining coins are still
|
|
113
|
+
returned to the caller. Its numeric route builder limits supported amounts to safe
|
|
114
|
+
JS integers; larger routes are explicitly rejected. Minimum output, health factor
|
|
115
|
+
and flash repayment checks remain enforced; extra fees can cause a PTB to abort
|
|
116
|
+
if those bounds cannot be met.
|
|
117
|
+
|
|
118
|
+
When calling the exported Astros converter directly, pass the real user address as
|
|
119
|
+
the fourth build argument: `converter.buildPTB(tx, quote, coin, { changeRecipient: address })`.
|
|
120
|
+
A missing, malformed or zero recipient is rejected before appending swap commands.
|
|
121
|
+
|
|
122
|
+
A custom `DataSource` must supply complete, coherent, verified Cap/position/risk/
|
|
123
|
+
price/fee data and prepare the oracle commands for its network. Failures must not
|
|
124
|
+
be converted to empty positions. Custom converters and data sources execute
|
|
125
|
+
trusted application code. Built-in deployments target **Sui mainnet**; passing a
|
|
126
|
+
testnet client alone does not switch their contract addresses.
|
|
127
|
+
|
|
128
|
+
## AccountCap and Vault integration
|
|
129
|
+
|
|
130
|
+
New Caps use `navi:multiply:v1:<strategyId>` as the name and the strategy definition
|
|
131
|
+
as the description. Existing Caps are reused after close. A default reader
|
|
132
|
+
excludes Caps registered to the Lending E-Mode product, validates strategy
|
|
133
|
+
metadata, and rejects duplicates. It never registers a Multiply Cap as an E-Mode
|
|
134
|
+
product Cap.
|
|
135
|
+
|
|
136
|
+
**One wallet/strategy is enforced by discovery and SDK checks only.** Two concurrent
|
|
137
|
+
transactions or direct contract calls can create duplicate names; renaming or
|
|
138
|
+
transferring a Cap can bypass this convention. A contract registry is needed for
|
|
139
|
+
a chain-enforced uniqueness guarantee. Names/descriptions are not authorization.
|
|
140
|
+
|
|
141
|
+
Auto Vault can inject a resolver for wrapped Caps and pass a PTB result through
|
|
142
|
+
`inputs.accountCap`. The resolver/caller is responsible for binding that transaction
|
|
143
|
+
result to the quoted Cap and snapshot; a transaction result cannot be authenticated
|
|
144
|
+
by its JS handle. Plain object-ID overrides must match the quoted ID. The engine
|
|
145
|
+
keeps Cap transfer/wrapping and final Coin custody with the caller, except for
|
|
146
|
+
Astros route change, which is refunded directly to `quote.address`. Vault integrations
|
|
147
|
+
must account for that refund policy or inject a converter with their custody policy.
|
|
148
|
+
|
|
149
|
+
Open API should retain quotes server-side or authenticate its quote envelope.
|
|
150
|
+
The SHA-256 checksum detects accidental mutation; it is **not** a signature or
|
|
151
|
+
permission to trust arbitrary client-supplied routes. A composed PTB must be
|
|
152
|
+
simulated by its caller before signing. HF, minimum conversion output, requested
|
|
153
|
+
principal output and optional maximum leverage are also enforced on chain. Close
|
|
154
|
+
reads the current balance in the PTB and asserts that both balances are zero.
|
|
155
|
+
|
|
156
|
+
## Initial release boundaries
|
|
157
|
+
|
|
158
|
+
- Built-in strategies: `vsuiSui`, `hasuiSui`, in their dedicated NAVI markets.
|
|
159
|
+
Main-market flash liquidity is independent of the position market.
|
|
160
|
+
- Principal must equal debt; collateral must be distinct. The default reader
|
|
161
|
+
currently supports nine-decimal pools. An unsupported E-Mode override is rejected.
|
|
162
|
+
- Delayed redemption/claim workflows, generic mixed-asset positions, cross-market
|
|
163
|
+
position aggregation, APY/history and on-chain unique-Cap registration are not
|
|
164
|
+
implemented. The data source checks assets in the selected market; it cannot
|
|
165
|
+
establish exclusive use of a Cap across every other market.
|
|
166
|
+
- Source reads and quote→build checks do not lock chain state. Changed liquidity,
|
|
167
|
+
prices or fees can make the transaction abort. Discard a partially built PTB
|
|
168
|
+
after a builder/network error; obtain a fresh quote rather than reuse it.
|
|
169
|
+
- Package publication is a separate release step. The implementation is accompanied
|
|
170
|
+
by mainnet simulation evidence, not signed/persisted chain transactions.
|
|
171
|
+
|
|
172
|
+
## Reproduce
|
|
173
|
+
|
|
174
|
+
From the monorepo root (Node 24 and pnpm 10.1.0 used for the recorded run):
|
|
175
|
+
|
|
176
|
+
```sh
|
|
177
|
+
pnpm install --frozen-lockfile
|
|
178
|
+
pnpm --filter @naviprotocol/lending --filter @naviprotocol/astros-aggregator-sdk build
|
|
179
|
+
pnpm --filter @naviprotocol/multiply typecheck
|
|
180
|
+
pnpm --filter @naviprotocol/multiply build
|
|
181
|
+
pnpm --filter @naviprotocol/multiply test:e2e
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
The test runner was committed before implementation (`57804f1`, with live-schema
|
|
185
|
+
fixture corrections in `fba268f`). No unit tests or mocked protocol implementations
|
|
186
|
+
were added. See [failure inventory](e2e/FAILURE-MATRIX.md) and [verification notes](docs/verification.md).
|
|
187
|
+
|
|
188
|
+
Each run writes input, frozen quotes, unsigned transaction bytes, commands, actual
|
|
189
|
+
post-operation balances/HF, simulation responses, a report and SHA-256 manifest
|
|
190
|
+
under `out/multiply/`. `MULTIPLY_E2E_ADDRESS` selects a **public funded simulation
|
|
191
|
+
address**; its key is neither read nor required. Defaults use the public NAVI
|
|
192
|
+
oracle sender. `MULTIPLY_E2E_ONLY` selects scenarios; only a complete run constitutes
|
|
193
|
+
full-suite evidence. Live chain state and service availability can change results.
|
|
194
|
+
The lifecycle fixture is real VM execution with a transient injected snapshot;
|
|
195
|
+
it does not prove persisted discovery or concurrent uniqueness.
|
|
196
|
+
|
|
197
|
+
The packed-package consumer replay is documented in the verification report.
|
|
198
|
+
|
|
199
|
+
The package pins published Lending 2.1.0 and Astros 2.0.7 dependencies. The clean
|
|
200
|
+
package consumer installs only the Multiply tarball locally and resolves these
|
|
201
|
+
dependencies from npm, without workspace links or dependency overrides.
|
|
@@ -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"}
|
package/dist/amounts.js
ADDED
|
@@ -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,IAAIA,EAAG,CAAC,EAAE,UAAUR,EAAcC,CAAI,IAAI,CAAC,CAAC;AACnE;AAEO,SAASW,EAAeF,GAAwB;AACrD,SAAOF,EAAG;AAAA,IACR;AAAA,IACA,IAAIA,EAAGE,EAAO,WAAW,UAAU,EAChC,UAAUV,EAAcU,EAAO,UAAU,CAAC,EAC1C,aAAaF,EAAG,WAAW;AAAA,EAAA;AAElC;AAEO,SAASK,EAAeH,GAAwB;AACrD,SAAO,IAAIF,EAAGJ,EAAaM,EAAO,KAAK,iBAAiBV,EAAcU,EAAO,IAAI,CAAC,CAAC;AACrF;AAGO,SAASI,EACdC,GACAC,GACAN,GACAO,GACA;AACA,QAAMC,IAAST,EAAWC,CAAM,GAC1B,IAAI,IAAIF,EAAGO,EAAU,gBAAgB,GACzCI,IAAI,IAAIX,EAAGO,EAAU,UAAU;AACjC,SACEI,EACG,MAAMD,EAAO,IAAI,EACjB,MAAMR,EAAO,YAAY,EACzB,IAAI,EAAE,MAAMQ,EAAO,UAAU,EAAE,MAAMR,EAAO,GAAG,CAAC,IAE5C,KAEPO,KACAE,EAAE,IAAIH,EAAO,UAAU,KACvBG,EAAE,MAAMH,EAAO,gBAAgB,EAAE,IAAI,IAAIR,EAAGQ,EAAO,UAAU,EAAE,MAAM,CAAC,CAAC;AAE3E;"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
2
|
+
import { Action, BuildInputs, BuildResult, Constraints, MultiplyOptions, MultiplyQuote, Position, Strategy } from './types.js';
|
|
3
|
+
|
|
4
|
+
export declare function createMultiplyClient(options?: MultiplyOptions): {
|
|
5
|
+
getPosition: (owner: string, query?: {
|
|
6
|
+
strategy?: Strategy;
|
|
7
|
+
}) => Promise<Position[]>;
|
|
8
|
+
quote: (owner: string, suppliedStrategy: Strategy, action: Action, constraints: Constraints) => Promise<MultiplyQuote>;
|
|
9
|
+
buildPTB: (tx: Transaction, suppliedQuote: MultiplyQuote, inputs: BuildInputs) => Promise<BuildResult>;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|