@naviprotocol/multiply 0.2.0-preview.20261118.2 → 0.2.0-preview.20261123.1

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
@@ -6,9 +6,9 @@ quotes and builds transactions; it never signs or broadcasts them.
6
6
  ## Phase 1 model
7
7
 
8
8
  The application owns product registration. Supply its validated `Strategy[]` to
9
- `createMultiplyClient`; the API's phase 1 directory uses four main-market pairs:
10
- vSUI/SUI, haSUI/SUI, SUI/USDC (long SUI), and USDSUI/USDC. This SDK release adds
11
- execution support; it does not approve their production risk policy.
9
+ `createMultiplyClient`. The API's phase 1 directory includes vSUI/SUI, haSUI/SUI,
10
+ and USDSUI/USDC. The application passes retired Registry keys alongside the active
11
+ strategies so wallet reads skip retired AccountCaps.
12
12
 
13
13
  A strategy has distinct collateral and debt tokens. `principalCoinType` can equal
14
14
  either. It is the accounting/default withdrawal unit, independent of the selected
@@ -24,17 +24,17 @@ const multiply = createMultiplyClient({
24
24
  strategies: productStrategies,
25
25
  retiredRegistryKeys: retiredProductKeys,
26
26
  })
27
- const strategy = productStrategies.find(s => s.id === 'long-sui')!
27
+ const strategy = productStrategies.find(s => s.id === 'main-vsui-sui')!
28
28
  const quote = await multiply.quote(
29
29
  address,
30
30
  strategy,
31
31
  { type: 'open', inputCoinType: strategy.collateralCoinType,
32
- amount: '1000000000', targetLeverage: '2' },
33
- { minHealthFactor: '1.6', maxSlippageBps: 50 }, // example, not approved risk policy
32
+ amount: '1000000000', targetLeverage: '1.5' },
33
+ { minHealthFactor: '2.0', maxSlippageBps: 50 },
34
34
  )
35
35
  const tx = new Transaction()
36
36
  const built = await multiply.buildPTB(tx, quote, {
37
- coins: [{ coinType: strategy.collateralCoinType, coin: suppliedSuiCoin }],
37
+ coins: [{ coinType: strategy.collateralCoinType, coin: suppliedVsuiCoin }],
38
38
  })
39
39
  if (built.createdAccountCap) tx.transferObjects([built.createdAccountCap], address)
40
40
  if (built.coins.length) tx.transferObjects(built.coins.map(c => c.coin), address)
@@ -83,7 +83,7 @@ Collateral input is supplied directly; only borrowed debt is converted. Debt
83
83
  input may merge with debt flash funding before conversion. A 1x collateral opening
84
84
  needs no conversion or flash loan. On a collateral-principal withdrawal/close,
85
85
  only the collateral required for debt repayment is sold; the remainder is returned
86
- as principal. Debt dust remains a separate output. Long SUI therefore exits in SUI.
86
+ as principal. Debt dust remains a separate output.
87
87
 
88
88
  The builder independently validates funding, conversion roles, projected balances,
89
89
  repayment math and minimum principal output. Different token types never merge.
@@ -113,8 +113,8 @@ safe integer range. When using the converter directly, pass a validated
113
113
 
114
114
  Keys `(strategyNumericId, strategyVersion)` are permanent execution identities,
115
115
  unique per registry definition. Never reassign a deployed key to different assets
116
- or market. New Caps are created and registered atomically; close retains the Cap.
117
- Invalid ownership, duplicate Caps/accounts, unsupported E-Mode and unknown keys
116
+ or market/mode. New Caps are created and registered atomically; close retains the Cap.
117
+ Invalid ownership, duplicate Caps/accounts, invalid E-Mode configuration and unknown keys
118
118
  fail explicitly. Only **explicit** `retiredRegistryKeys` may be skipped; structural,
119
119
  identity and duplicate checks still run first. Retiring a key does not move funds.
120
120
 
@@ -134,8 +134,8 @@ The API consequently reports lifetime yield unavailable until a conforming sourc
134
134
  and complete history watermark are available. Basic positions and risk still work.
135
135
 
136
136
  Custom adapters are trusted application code. Built-in contract deployments target
137
- Sui mainnet; changing only the client URL does not switch those addresses. E-Mode,
138
- isolated phase 2, third-token inputs and delayed redemption are out of scope.
137
+ Sui mainnet; changing only the client URL does not switch those addresses.
138
+ Isolated phase 2, third-token inputs and delayed redemption are out of scope.
139
139
  The exported `strategies.vsuiSui`/`hasuiSui` remain legacy dedicated-market presets
140
140
  (keys 1:1/2:1); phase 1 products must use the API-owned main-market registry.
141
141
 
@@ -161,3 +161,22 @@ threshold fallback and malformed/retired identities. Historical documents under
161
161
  phase 1 hosted simulation or signed-wallet acceptance. Each product must progress
162
162
  through open simulation → human sample creation → management simulation → human
163
163
  management/close, with matching Registry keys and source/artifact revisions.
164
+
165
+ ### Strategy E-Mode
166
+
167
+ Set `Strategy.emodeId` together with `market` to use that market's E-Mode (ID `0`
168
+ is valid). `getMarket()` supplies the configured group's collateral LTV/LT;
169
+ debt retains its reserve borrow weight. The data source checks asset direction.
170
+
171
+ Use a **new Multiply Registry strategyVersion** when switching a strategy's mode,
172
+ and retire the previous key through `retiredRegistryKeys`. Existing ordinary Caps
173
+ are not migrated. A newly created Cap enters the configured mode in the same PTB,
174
+ before Multiply registration and funding. A previously initialized Cap, including
175
+ an empty one reopened after close, is reused without a mode query or another enter.
176
+ No operation reads or writes the independent E-Mode Registry.
177
+
178
+ Custom DataSources must return `market.emode = { id, active }` for E-Mode strategies,
179
+ alongside their effective risk parameters. Paused groups disable new exposure;
180
+ the default source can read only that group's configuration to support repayment
181
+ and exit, without reading any account's current mode. Keep the existing final-byte
182
+ simulation requirement, especially with `buildPTBForSimulation`.
package/dist/amounts.d.ts CHANGED
@@ -1,10 +1,16 @@
1
1
  import { Pool } from '@naviprotocol/lending';
2
- import { MarketSnapshot, PositionAmounts } from './types.js';
2
+ import { MarketSnapshot, PositionAmounts, Strategy } from './types.js';
3
3
 
4
4
  /** NAVI stores lending balances/capacity at 9 decimals, independently of Coin<T>. */
5
5
  export declare const LENDING_DECIMALS = 9;
6
6
  export declare function tokenDecimals(pool: Pick<Pool, 'token'>): number;
7
7
  export declare function lendingToRaw(value: string, decimals: number, roundUp?: boolean): string;
8
+ /** A custom source with a rounded-down zero cannot establish an empty Cap without the protocol amount. */
9
+ export declare function positionSides(position: PositionAmounts, market: MarketSnapshot): {
10
+ collateral: boolean;
11
+ debt: boolean;
12
+ };
13
+ export declare function isDustClose(strategy: Strategy, position: PositionAmounts, market: MarketSnapshot): boolean;
8
14
  /** Price of one native atom, used only inside the solver. Public prices stay USD/token. */
9
15
  export declare function atomPrices(market: MarketSnapshot): {
10
16
  collateral: import('bignumber.js').BigNumber;
@@ -1 +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"}
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,QAAQ,EAAE,MAAM,SAAS,CAAA;AAGxE,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,0GAA0G;AAC1G,wBAAgB,aAAa,CAAC,QAAQ,EAAE,eAAe,EAAE,MAAM,EAAE,cAAc;;;EA2B9E;AAED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,EAAE,cAAc,WAUhG;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 CHANGED
@@ -1,46 +1,71 @@
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;
1
+ import { decimal as i, BN as l, check as s } from "./utils.js";
2
+ const d = 9;
3
+ function o(t) {
4
+ const e = t.token?.decimals;
5
5
  return s(
6
- Number.isInteger(n) && n >= 0 && n <= 18,
6
+ Number.isInteger(e) && e >= 0 && e <= 18,
7
7
  "MARKET_UNSUPPORTED",
8
8
  "Token precision must be an integer from 0 to 18"
9
- ), n;
9
+ ), e;
10
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);
11
+ function m(t, e, n = !1) {
12
+ return i(t).shiftedBy(e - d).integerValue(n ? l.ROUND_CEIL : l.ROUND_FLOOR).toFixed(0);
13
+ }
14
+ function b(t, e) {
15
+ const n = (u, r, c, a) => r !== void 0 ? (s(
16
+ /^(0|[1-9][0-9]{0,77})$/.test(r) && m(r, c, a) === u,
17
+ "READ_FAILED",
18
+ "Invalid protocol balance or inconsistent native amount"
19
+ ), r !== "0") : (s(
20
+ a || c >= d || u !== "0",
21
+ "READ_FAILED",
22
+ "Rounded collateral requires a protocol balance"
23
+ ), u !== "0");
24
+ return {
25
+ collateral: n(
26
+ t.collateralAmount,
27
+ t.protocolCollateralAmount,
28
+ o(e.collateral),
29
+ !1
30
+ ),
31
+ debt: n(t.debtAmount, t.protocolDebtAmount, o(e.debt), !0)
32
+ };
33
+ }
34
+ function D(t, e, n) {
35
+ return t.allowCollateralDustClose === !0 && o(n.collateral) === 6 && e.collateralAmount === "0" && e.debtAmount === "0" && e.protocolDebtAmount === "0" && typeof e.protocolCollateralAmount == "string" && /^[1-9][0-9]{0,2}$/.test(e.protocolCollateralAmount);
13
36
  }
14
37
  function f(t) {
15
38
  return {
16
- collateral: r(t.collateralPrice).shiftedBy(-l(t.collateral)),
17
- debt: r(t.debtPrice).shiftedBy(-l(t.debt))
39
+ collateral: i(t.collateralPrice).shiftedBy(-o(t.collateral)),
40
+ debt: i(t.debtPrice).shiftedBy(-o(t.debt))
18
41
  };
19
42
  }
20
43
  function w(t) {
21
- return e.maximum(1, new e(1).shiftedBy(l(t) - 6));
44
+ return l.maximum(1, new l(1).shiftedBy(o(t) - 6));
22
45
  }
23
- function h(t) {
24
- return e.maximum(
46
+ function C(t) {
47
+ return l.maximum(
25
48
  0,
26
- new e(t.collateral.leftSupply).shiftedBy(l(t.collateral)).integerValue(e.ROUND_FLOOR)
49
+ new l(t.collateral.leftSupply).shiftedBy(o(t.collateral)).integerValue(l.ROUND_FLOOR)
27
50
  );
28
51
  }
29
- function p(t) {
30
- return new e(d(t.debt.availableBorrow, l(t.debt)));
52
+ function R(t) {
53
+ return new l(m(t.debt.availableBorrow, o(t.debt)));
31
54
  }
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));
55
+ function y(t, e, n, u) {
56
+ const r = f(n), c = new l(t.collateralAmount), a = new l(t.debtAmount);
57
+ return a.times(r.debt).times(n.borrowWeight).lte(c.times(r.collateral).times(n.ltv)) ? !0 : u && a.lte(e.debtAmount) && a.times(e.collateralAmount).lte(new l(e.debtAmount).times(c));
35
58
  }
36
59
  export {
37
- m as LENDING_DECIMALS,
60
+ d as LENDING_DECIMALS,
38
61
  w as amountCushion,
39
62
  f as atomPrices,
40
- p as borrowCapacity,
41
- d as lendingToRaw,
42
- h as supplyCapacity,
43
- l as tokenDecimals,
63
+ R as borrowCapacity,
64
+ D as isDustClose,
65
+ m as lendingToRaw,
66
+ b as positionSides,
67
+ C as supplyCapacity,
68
+ o as tokenDecimals,
44
69
  y as withinLtv
45
70
  };
46
71
  //# sourceMappingURL=amounts.js.map
@@ -1 +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,CAA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"],"sourcesContent":["import type { Pool } from '@naviprotocol/lending'\nimport type { MarketSnapshot, PositionAmounts, Strategy } 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/** A custom source with a rounded-down zero cannot establish an empty Cap without the protocol amount. */\nexport function positionSides(position: PositionAmounts, market: MarketSnapshot) {\n const side = (amount: string, protocol: string | undefined, decimals: number, debt: boolean) => {\n if (protocol !== undefined) {\n check(\n /^(0|[1-9][0-9]{0,77})$/.test(protocol) &&\n lendingToRaw(protocol, decimals, debt) === amount,\n 'READ_FAILED',\n 'Invalid protocol balance or inconsistent native amount'\n )\n return protocol !== '0'\n }\n check(\n debt || decimals >= LENDING_DECIMALS || amount !== '0',\n 'READ_FAILED',\n 'Rounded collateral requires a protocol balance'\n )\n return amount !== '0'\n }\n return {\n collateral: side(\n position.collateralAmount,\n position.protocolCollateralAmount,\n tokenDecimals(market.collateral),\n false\n ),\n debt: side(position.debtAmount, position.protocolDebtAmount, tokenDecimals(market.debt), true)\n }\n}\n\nexport function isDustClose(strategy: Strategy, position: PositionAmounts, market: MarketSnapshot) {\n return (\n strategy.allowCollateralDustClose === true &&\n tokenDecimals(market.collateral) === 6 &&\n position.collateralAmount === '0' &&\n position.debtAmount === '0' &&\n position.protocolDebtAmount === '0' &&\n typeof position.protocolCollateralAmount === 'string' &&\n /^[1-9][0-9]{0,2}$/.test(position.protocolCollateralAmount)\n )\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","positionSides","position","market","side","amount","protocol","debt","isDustClose","strategy","atomPrices","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;A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AOO,EAAG,QAAQ,GAAG,IAAIA,EAAG,CAAC,EAAE,UAAUR,EAAcC,CAAI,IAAI,CAAC,CAAC;AACnE;AAEO,SAASmB,EAAeT,GAAwB;AACrD,SAAOH,EAAG;AAAA,IACR;AAAA,IACA,IAAIA,EAAGG,EAAO,WAAW,UAAU,EAChC,UAAUX,EAAcW,EAAO,UAAU,CAAC,EAC1C,aAAaH,EAAG,WAAW;AAAA,EAAA;AAElC;AAEO,SAASa,EAAeV,GAAwB;AACrD,SAAO,IAAIH,EAAGJ,EAAaO,EAAO,KAAK,iBAAiBX,EAAcW,EAAO,IAAI,CAAC,CAAC;AACrF;AAGO,SAASW,EACdC,GACAC,GACAb,GACAc,GACA;AACA,QAAMC,IAASR,EAAWP,CAAM,GAC1B,IAAI,IAAIH,EAAGe,EAAU,gBAAgB,GACzCI,IAAI,IAAInB,EAAGe,EAAU,UAAU;AACjC,SACEI,EACG,MAAMD,EAAO,IAAI,EACjB,MAAMf,EAAO,YAAY,EACzB,IAAI,EAAE,MAAMe,EAAO,UAAU,EAAE,MAAMf,EAAO,GAAG,CAAC,IAE5C,KAEPc,KACAE,EAAE,IAAIH,EAAO,UAAU,KACvBG,EAAE,MAAMH,EAAO,gBAAgB,EAAE,IAAI,IAAIhB,EAAGgB,EAAO,UAAU,EAAE,MAAM,CAAC,CAAC;AAE3E;"}
package/dist/client.d.ts CHANGED
@@ -6,6 +6,7 @@ export declare function createMultiplyClient(options?: MultiplyOptions): {
6
6
  strategy?: Strategy;
7
7
  }) => Promise<Position[]>;
8
8
  quote: (owner: string, suppliedStrategy: Strategy, action: Action, constraints: Constraints) => Promise<MultiplyQuote>;
9
- buildPTB: (tx: Transaction, suppliedQuote: MultiplyQuote, inputs: BuildInputs) => Promise<BuildResult>;
9
+ buildPTB: (tx: Transaction, q: MultiplyQuote, inputs: BuildInputs) => Promise<BuildResult>;
10
+ buildPTBForSimulation: (tx: Transaction, q: MultiplyQuote, coins: BuildInputs["coins"]) => Promise<BuildResult>;
10
11
  };
11
12
  //# sourceMappingURL=client.d.ts.map
@@ -1 +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;AAiChB,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,eAAoB;yBA2IvD,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;mBAmFnB,WAAW,iBACA,aAAa,UACpB,WAAW,KAClB,OAAO,CAAC,WAAW,CAAC;EAuexB"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,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;AAmChB,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,eAAoB;yBA4IvD,MAAM,UACN;QAAE,QAAQ,CAAC,EAAE,QAAQ,CAAA;KAAE,KAC7B,OAAO,CAAC,QAAQ,EAAE,CAAC;mBAwBb,MAAM,oBACK,QAAQ,UAClB,MAAM,eACD,WAAW,KACvB,OAAO,CAAC,aAAa,CAAC;mBA2oBH,WAAW,KAAK,aAAa,UAAU,WAAW;gCAKrC,WAAW,KAAK,aAAa,SAAS,WAAW,CAAC,OAAO,CAAC;EAK9F"}