@naviprotocol/multiply 0.2.0-preview.20261102.1 → 0.2.0-preview.20261103.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 +42 -10
- 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/cap-registry.d.ts +18 -0
- package/dist/cap-registry.d.ts.map +1 -0
- package/dist/cap-registry.js +85 -0
- package/dist/cap-registry.js.map +1 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +365 -295
- package/dist/client.js.map +1 -1
- package/dist/data-source.d.ts +4 -2
- package/dist/data-source.d.ts.map +1 -1
- package/dist/data-source.js +218 -172
- package/dist/data-source.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -15
- package/dist/index.js.map +1 -1
- package/dist/planner.d.ts +1 -1
- package/dist/planner.d.ts.map +1 -1
- package/dist/planner.js +196 -150
- package/dist/planner.js.map +1 -1
- package/dist/strategies.d.ts +8 -1
- package/dist/strategies.d.ts.map +1 -1
- package/dist/strategies.js +13 -12
- package/dist/strategies.js.map +1 -1
- package/dist/types.d.ts +19 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -1
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 3; earlier 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,
|
|
@@ -102,16 +127,23 @@ testnet client alone does not switch their contract addresses.
|
|
|
102
127
|
|
|
103
128
|
## AccountCap and Vault integration
|
|
104
129
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
130
|
+
Caps are discovered exclusively through the mainnet Multiply Registry. Fixed keys
|
|
131
|
+
`(strategyNumericId, strategyVersion)` bind vSUI/SUI to `(1,1)`, haSUI/SUI to `(2,1)`;
|
|
132
|
+
Open API additionally configures short SUI as `(3,1)`. Every custom Strategy must
|
|
133
|
+
supply a unique `registryKey` with canonical integer strings. The version is below
|
|
134
|
+
100000 and the combined key must fit u64; never reassign a key to different assets.
|
|
135
|
+
|
|
136
|
+
New Caps are created and registered atomically in the opening PTB. The registry
|
|
137
|
+
rejects a duplicate key for the same sender. The reader verifies object type,
|
|
138
|
+
ownership and accountOwner, rejects duplicate Cap/accounts and E-Mode product Caps.
|
|
139
|
+
Names/descriptions are neither read nor written. Unregistered Caps are intentionally
|
|
140
|
+
excluded, with no migration or wallet-scan fallback. Close retains the registered Cap.
|
|
141
|
+
Invalid or transferred registered Caps fail explicitly rather than creating replacements.
|
|
142
|
+
|
|
143
|
+
`createNaviDataSource({ client, capRegistry, strategies })` and the engine must share
|
|
144
|
+
the same deployment and definitions. A custom DataSource declares its `capRegistry`.
|
|
145
|
+
Quote/build bind these settings and the fixed numeric key; transaction sender must
|
|
146
|
+
match quote.address. Unknown keys fail with `UNSUPPORTED_REGISTRY_STRATEGY`.
|
|
115
147
|
|
|
116
148
|
Auto Vault can inject a resolver for wrapped Caps and pass a PTB result through
|
|
117
149
|
`inputs.accountCap`. The resolver/caller is responsible for binding that transaction
|
|
@@ -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;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
2
|
+
import { CapRegistryConfig, RegistryKey, Strategy } from './types.js';
|
|
3
|
+
|
|
4
|
+
export declare const ACCOUNT_CAP_TYPE = "0x66c91a8560cd64d73d93dd1ec7b61f3f21ad2f66553dd3d7038ca69255479bb7::account::AccountCap";
|
|
5
|
+
export declare const MAINNET_CAP_REGISTRY: Readonly<CapRegistryConfig>;
|
|
6
|
+
export declare function normalizeCapRegistry(config: CapRegistryConfig): CapRegistryConfig;
|
|
7
|
+
export declare function registryKeyString(key: RegistryKey): string;
|
|
8
|
+
export declare function indexRegistryStrategies(strategies: Strategy[]): Map<string, Strategy>;
|
|
9
|
+
export interface RegistryEntry {
|
|
10
|
+
registryKey: RegistryKey;
|
|
11
|
+
capId: string;
|
|
12
|
+
}
|
|
13
|
+
/** Decode all rows before using any of them. A malformed response is never an empty registry. */
|
|
14
|
+
export declare function decodeRegistryEntries(values: {
|
|
15
|
+
bcs: Uint8Array;
|
|
16
|
+
}[]): RegistryEntry[];
|
|
17
|
+
export declare function registerCreatedCapPTB(tx: Transaction, cap: TransactionObjectArgument, key: RegistryKey, deployment: CapRegistryConfig): void;
|
|
18
|
+
//# sourceMappingURL=cap-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cap-registry.d.ts","sourceRoot":"","sources":["../src/cap-registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAA;AACtF,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAGvE,eAAO,MAAM,gBAAgB,4FAC8D,CAAA;AAE3F,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,iBAAiB,CAI3D,CAAA;AAEF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,iBAAiB,GAAG,iBAAiB,CAUjF;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,CAU1D;AAED,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAWrF;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,WAAW,CAAA;IACxB,KAAK,EAAE,MAAM,CAAA;CACd;AAED,iGAAiG;AACjG,wBAAgB,qBAAqB,CAAC,MAAM,EAAE;IAAE,GAAG,EAAE,UAAU,CAAA;CAAE,EAAE,GAAG,aAAa,EAAE,CA+BpF;AAED,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,WAAW,EACf,GAAG,EAAE,yBAAyB,EAC9B,GAAG,EAAE,WAAW,EAChB,UAAU,EAAE,iBAAiB,QAkB9B"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { bcs as c } from "@mysten/sui/bcs";
|
|
2
|
+
import { check as s, address as d, uint as u, U64_MAX as I } from "./utils.js";
|
|
3
|
+
const p = "0x66c91a8560cd64d73d93dd1ec7b61f3f21ad2f66553dd3d7038ca69255479bb7::account::AccountCap", R = Object.freeze({
|
|
4
|
+
network: "sui:mainnet",
|
|
5
|
+
packageId: "0xe98ff1aab2414aa2e60d0561284d011b3c486d47313b51700a2691ad4d37b162",
|
|
6
|
+
objectId: "0x1fb36a5acfcb96b75f0be8869fd6acebbe7586e3e271b81ae4cdcb8ae4ebdd39"
|
|
7
|
+
});
|
|
8
|
+
function A(e) {
|
|
9
|
+
s(e?.network === "sui:mainnet", "INVALID_ARGUMENT", "Unsupported Registry network");
|
|
10
|
+
const r = d(e.packageId), t = d(e.objectId);
|
|
11
|
+
return s(
|
|
12
|
+
r !== d("0x0") && t !== d("0x0"),
|
|
13
|
+
"INVALID_ARGUMENT",
|
|
14
|
+
"Zero Registry address"
|
|
15
|
+
), Object.freeze({ network: e.network, packageId: r, objectId: t });
|
|
16
|
+
}
|
|
17
|
+
function b(e) {
|
|
18
|
+
s(e, "INVALID_ARGUMENT", "Missing strategy Registry key");
|
|
19
|
+
const r = u(e.strategyNumericId, !1), t = u(e.strategyVersion, !1);
|
|
20
|
+
return s(
|
|
21
|
+
t < 100000n && r * 100000n + t <= I,
|
|
22
|
+
"INVALID_ARGUMENT",
|
|
23
|
+
"Strategy Registry key is outside contract range"
|
|
24
|
+
), `${r}:${t}`;
|
|
25
|
+
}
|
|
26
|
+
function _(e) {
|
|
27
|
+
const r = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Set();
|
|
28
|
+
for (const n of e) {
|
|
29
|
+
const a = b(n.registryKey);
|
|
30
|
+
s(!t.has(n.id), "INVALID_ARGUMENT", "Strategy registry contains duplicate ids"), s(!r.has(a), "INVALID_ARGUMENT", "Strategy registry contains duplicate numeric keys"), t.add(n.id), r.set(a, n);
|
|
31
|
+
}
|
|
32
|
+
return r;
|
|
33
|
+
}
|
|
34
|
+
function m(e) {
|
|
35
|
+
try {
|
|
36
|
+
s(e?.length === 3, "READ_FAILED", "Invalid Registry return values");
|
|
37
|
+
const r = c.vector(c.u64()).parse(e[0].bcs), t = c.vector(c.u64()).parse(e[1].bcs), n = c.vector(c.Address).parse(e[2].bcs);
|
|
38
|
+
s(
|
|
39
|
+
r.length === t.length && r.length === n.length,
|
|
40
|
+
"READ_FAILED",
|
|
41
|
+
"Registry arrays differ in length"
|
|
42
|
+
);
|
|
43
|
+
const a = /* @__PURE__ */ new Set();
|
|
44
|
+
return r.map((i, g) => {
|
|
45
|
+
const o = t[g], y = `${i}:${o}`;
|
|
46
|
+
return s(
|
|
47
|
+
BigInt(o) < 100000n && BigInt(i) * 100000n + BigInt(o) <= I && !a.has(y),
|
|
48
|
+
"READ_FAILED",
|
|
49
|
+
"Invalid or duplicate Registry key"
|
|
50
|
+
), a.add(y), {
|
|
51
|
+
registryKey: { strategyNumericId: i, strategyVersion: o },
|
|
52
|
+
capId: d(n[g])
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
} catch {
|
|
56
|
+
s(!1, "READ_FAILED", "Unable to decode complete Multiply Registry");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function E(e, r, t, n) {
|
|
60
|
+
b(t);
|
|
61
|
+
const a = A(n), i = e.moveCall({
|
|
62
|
+
target: "0x2::object::id_address",
|
|
63
|
+
typeArguments: [p],
|
|
64
|
+
arguments: [r]
|
|
65
|
+
});
|
|
66
|
+
e.moveCall({
|
|
67
|
+
target: `${a.packageId}::multiply_registry::register_mul_for_account_cap`,
|
|
68
|
+
arguments: [
|
|
69
|
+
e.object(a.objectId),
|
|
70
|
+
i,
|
|
71
|
+
e.pure.u64(t.strategyNumericId),
|
|
72
|
+
e.pure.u64(t.strategyVersion)
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
p as ACCOUNT_CAP_TYPE,
|
|
78
|
+
R as MAINNET_CAP_REGISTRY,
|
|
79
|
+
m as decodeRegistryEntries,
|
|
80
|
+
_ as indexRegistryStrategies,
|
|
81
|
+
A as normalizeCapRegistry,
|
|
82
|
+
E as registerCreatedCapPTB,
|
|
83
|
+
b as registryKeyString
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=cap-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cap-registry.js","sources":["../src/cap-registry.ts"],"sourcesContent":["import { bcs } from '@mysten/sui/bcs'\nimport type { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions'\nimport type { CapRegistryConfig, RegistryKey, Strategy } from './types'\nimport { address, check, U64_MAX, uint } from './utils'\n\nexport const ACCOUNT_CAP_TYPE =\n '0x66c91a8560cd64d73d93dd1ec7b61f3f21ad2f66553dd3d7038ca69255479bb7::account::AccountCap'\n\nexport const MAINNET_CAP_REGISTRY: Readonly<CapRegistryConfig> = Object.freeze({\n network: 'sui:mainnet',\n packageId: '0xe98ff1aab2414aa2e60d0561284d011b3c486d47313b51700a2691ad4d37b162',\n objectId: '0x1fb36a5acfcb96b75f0be8869fd6acebbe7586e3e271b81ae4cdcb8ae4ebdd39'\n})\n\nexport function normalizeCapRegistry(config: CapRegistryConfig): CapRegistryConfig {\n check(config?.network === 'sui:mainnet', 'INVALID_ARGUMENT', 'Unsupported Registry network')\n const packageId = address(config.packageId),\n objectId = address(config.objectId)\n check(\n packageId !== address('0x0') && objectId !== address('0x0'),\n 'INVALID_ARGUMENT',\n 'Zero Registry address'\n )\n return Object.freeze({ network: config.network, packageId, objectId })\n}\n\nexport function registryKeyString(key: RegistryKey): string {\n check(key, 'INVALID_ARGUMENT', 'Missing strategy Registry key')\n const id = uint(key.strategyNumericId, false),\n version = uint(key.strategyVersion, false)\n check(\n version < 100000n && id * 100000n + version <= U64_MAX,\n 'INVALID_ARGUMENT',\n 'Strategy Registry key is outside contract range'\n )\n return `${id}:${version}`\n}\n\nexport function indexRegistryStrategies(strategies: Strategy[]): Map<string, Strategy> {\n const byKey = new Map<string, Strategy>(),\n ids = new Set<string>()\n for (const strategy of strategies) {\n const key = registryKeyString(strategy.registryKey)\n check(!ids.has(strategy.id), 'INVALID_ARGUMENT', 'Strategy registry contains duplicate ids')\n check(!byKey.has(key), 'INVALID_ARGUMENT', 'Strategy registry contains duplicate numeric keys')\n ids.add(strategy.id)\n byKey.set(key, strategy)\n }\n return byKey\n}\n\nexport interface RegistryEntry {\n registryKey: RegistryKey\n capId: string\n}\n\n/** Decode all rows before using any of them. A malformed response is never an empty registry. */\nexport function decodeRegistryEntries(values: { bcs: Uint8Array }[]): RegistryEntry[] {\n try {\n check(values?.length === 3, 'READ_FAILED', 'Invalid Registry return values')\n const ids = bcs.vector(bcs.u64()).parse(values[0].bcs)\n const versions = bcs.vector(bcs.u64()).parse(values[1].bcs)\n const caps = bcs.vector(bcs.Address).parse(values[2].bcs)\n check(\n ids.length === versions.length && ids.length === caps.length,\n 'READ_FAILED',\n 'Registry arrays differ in length'\n )\n const keys = new Set<string>()\n return ids.map((id, i) => {\n const version = versions[i],\n key = `${id}:${version}`\n check(\n BigInt(version) < 100000n &&\n BigInt(id) * 100000n + BigInt(version) <= U64_MAX &&\n !keys.has(key),\n 'READ_FAILED',\n 'Invalid or duplicate Registry key'\n )\n keys.add(key)\n return {\n registryKey: { strategyNumericId: id, strategyVersion: version },\n capId: address(caps[i])\n }\n })\n } catch {\n check(false, 'READ_FAILED', 'Unable to decode complete Multiply Registry')\n }\n}\n\nexport function registerCreatedCapPTB(\n tx: Transaction,\n cap: TransactionObjectArgument,\n key: RegistryKey,\n deployment: CapRegistryConfig\n) {\n registryKeyString(key)\n const config = normalizeCapRegistry(deployment)\n const capAddress = tx.moveCall({\n target: '0x2::object::id_address',\n typeArguments: [ACCOUNT_CAP_TYPE],\n arguments: [cap]\n })\n tx.moveCall({\n target: `${config.packageId}::multiply_registry::register_mul_for_account_cap`,\n arguments: [\n tx.object(config.objectId),\n capAddress,\n tx.pure.u64(key.strategyNumericId),\n tx.pure.u64(key.strategyVersion)\n ]\n })\n}\n"],"names":["ACCOUNT_CAP_TYPE","MAINNET_CAP_REGISTRY","normalizeCapRegistry","config","check","packageId","address","objectId","registryKeyString","key","id","uint","version","U64_MAX","indexRegistryStrategies","strategies","byKey","ids","strategy","decodeRegistryEntries","values","bcs","versions","caps","keys","i","registerCreatedCapPTB","tx","cap","deployment","capAddress"],"mappings":"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"}
|
package/dist/client.d.ts.map
CHANGED
|
@@ -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;
|
|
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;AAgChB,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,eAAoB;yBAqHvD,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;mBA0EnB,WAAW,iBACA,aAAa,UACpB,WAAW,KAClB,OAAO,CAAC,WAAW,CAAC;EAmdxB"}
|