@ember-finance/sdk 2.14.0 → 2.15.0

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,8 +1,8 @@
1
1
  import { bcs } from "@mysten/sui/bcs";
2
+ import { tableIdOf, unwrapMoveFields } from "../utils/common.js";
2
3
  import { computeSwapQuote, computePlainInstantQuote } from "../../atomic/instant-withdraw.js";
3
4
  /** Sui fixed-point scale (1e9) used by the Atomic Liquidity Vault Move math. */
4
5
  const SUI_SCALE = 1000000000n;
5
- const unwrapMoveFields = (value) => value?.fields ?? value;
6
6
  const toBig = (v) => v === undefined || v === null ? 0n : BigInt(v);
7
7
  /** `math::div(a, b)` = floor(a * scale / b). */
8
8
  const divFloor = (a, b) => (b === 0n ? 0n : (a * SUI_SCALE) / b);
@@ -73,7 +73,7 @@ export class SuiAtomicLiquidityReader {
73
73
  /** Per-source-share EmberShare config from the `ember_share_configs` table. */
74
74
  async getEmberShareConfig(vaultId, sourceVaultId) {
75
75
  const fields = await this.vaultFields(vaultId);
76
- const tableId = unwrapMoveFields(fields.ember_share_configs)?.id?.id;
76
+ const tableId = tableIdOf(fields.ember_share_configs);
77
77
  if (!tableId)
78
78
  return null;
79
79
  {
@@ -102,7 +102,7 @@ export class SuiAtomicLiquidityReader {
102
102
  /** Caller's ALV (non-transferable) share balance from the `shares` table. */
103
103
  async shareOf(vaultId, account) {
104
104
  const fields = await this.vaultFields(vaultId);
105
- const tableId = unwrapMoveFields(fields.shares)?.id?.id;
105
+ const tableId = tableIdOf(fields.shares);
106
106
  if (!tableId)
107
107
  return 0n;
108
108
  return toBig(await this.readTableValue(tableId, "address", account));
@@ -466,7 +466,7 @@ export declare class TxBuilder {
466
466
  * @param options Optional tx building params
467
467
  * @returns TransactionBlock
468
468
  */
469
- atomicSetEmberShareWhitelist(vaultId: string, shareVaultId: string, whitelisted: boolean, feePercentage: NumStr, maxCapacityPercentage: NumStr, holdbackPercentage: NumStr, maxUtilizationPercentage: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
469
+ atomicSetEmberShareWhitelist(vaultId: string, shareVaultId: string, whitelisted: boolean, feePercentage: NumStr, maxCapacityPercentage: NumStr, holdbackPercentage: NumStr, maxUtilizationPercentage: NumStr, minSwapGross: NumStr, maxHeldValueAbsolute: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
470
470
  /**
471
471
  * Sets the max utilization percentage of an ember share source vault
472
472
  * @param vaultId Id of the atomic vault
@@ -556,7 +556,7 @@ export declare class TxBuilder {
556
556
  * @param options Optional tx building params
557
557
  * @returns TransactionBlock
558
558
  */
559
- atomicSetStrategyNoneFromAlphalend(vaultId: string, lendingProtocolId: string, options?: ITxBuilderOptionalParams): TransactionBlock;
559
+ atomicSetStrategyNoneFromAlphalend(vaultId: string, lendingProtocolId: string, acceptResidual: boolean, options?: ITxBuilderOptionalParams): TransactionBlock;
560
560
  /**
561
561
  * Step 1 of 2 for Suilend activation: commits the reserve index, the market
562
562
  * object and the collateral type. Step 2 is `atomicOpenSuilendObligation`,
@@ -1452,7 +1452,7 @@ export class TxBuilder {
1452
1452
  * @param options Optional tx building params
1453
1453
  * @returns TransactionBlock
1454
1454
  */
1455
- atomicSetEmberShareWhitelist(vaultId, shareVaultId, whitelisted, feePercentage, maxCapacityPercentage, holdbackPercentage, maxUtilizationPercentage, options) {
1455
+ atomicSetEmberShareWhitelist(vaultId, shareVaultId, whitelisted, feePercentage, maxCapacityPercentage, holdbackPercentage, maxUtilizationPercentage, minSwapGross, maxHeldValueAbsolute, options) {
1456
1456
  const txb = options?.txBlock || new TransactionBlock();
1457
1457
  txb.moveCall({
1458
1458
  arguments: [
@@ -1463,7 +1463,9 @@ export class TxBuilder {
1463
1463
  txb.pure.u64(feePercentage),
1464
1464
  txb.pure.u64(maxCapacityPercentage),
1465
1465
  txb.pure.u64(holdbackPercentage),
1466
- txb.pure.u64(maxUtilizationPercentage)
1466
+ txb.pure.u64(maxUtilizationPercentage),
1467
+ txb.pure.u64(minSwapGross),
1468
+ txb.pure.u64(maxHeldValueAbsolute)
1467
1469
  ],
1468
1470
  typeArguments: [this.parser.getAtomicCollateralType(vaultId)],
1469
1471
  target: `${this.parser.getPackageId()}::gateway::atomic_set_ember_share_whitelist`
@@ -1715,13 +1717,14 @@ export class TxBuilder {
1715
1717
  * @param options Optional tx building params
1716
1718
  * @returns TransactionBlock
1717
1719
  */
1718
- atomicSetStrategyNoneFromAlphalend(vaultId, lendingProtocolId, options) {
1720
+ atomicSetStrategyNoneFromAlphalend(vaultId, lendingProtocolId, acceptResidual, options) {
1719
1721
  const txb = options?.txBlock || new TransactionBlock();
1720
1722
  txb.moveCall({
1721
1723
  arguments: [
1722
1724
  txb.object(vaultId),
1723
1725
  txb.object(this.parser.getProtocolConfig()),
1724
1726
  txb.object(lendingProtocolId),
1727
+ txb.pure.bool(acceptResidual),
1725
1728
  txb.object(SUI_CLOCK_OBJECT_ID)
1726
1729
  ],
1727
1730
  typeArguments: [this.parser.getAtomicCollateralType(vaultId)],
@@ -2383,7 +2386,11 @@ export class TxBuilder {
2383
2386
  arguments: [
2384
2387
  txb.object(vaultId),
2385
2388
  txb.object(this.parser.getProtocolConfig()),
2386
- txb.pure.id(sourceVaultId),
2389
+ // `source_vault: &Vault<T, R>` — a shared-object reference, not an
2390
+ // id. Its sibling `atomic_redeem_collected_ember_shares` takes the
2391
+ // same vault the same way; sending a pure ID here cannot resolve to
2392
+ // the object the Move side wants.
2393
+ txb.object(sourceVaultId),
2387
2394
  txb.object(tokenId)
2388
2395
  ],
2389
2396
  typeArguments: [
@@ -193,10 +193,15 @@ export declare class VaultAdminCalls extends OnChainCalls {
193
193
  * @param maxCapacityPercentage The max capacity percentage
194
194
  * @param holdbackPercentage The holdback percentage
195
195
  * @param maxUtilizationPercentage The max utilization percentage
196
+ * @param minSwapGross Minimum gross swap size, in collateral base units. 0 means
197
+ * no floor. Below it `swap_ember_shares` aborts, which is what keeps dust swaps
198
+ * from walking the fee curve for free.
199
+ * @param maxHeldValueAbsolute Absolute ceiling on the collateral value this vault
200
+ * will custody for the source. 0 means no cap — the percentage caps still apply.
196
201
  * @param options Optional tx execution params
197
202
  * @returns OnChainCallResponse
198
203
  */
199
- atomicSetEmberShareWhitelist(vaultId: string, shareVaultId: string, whitelisted: boolean, feePercentage: NumStr, maxCapacityPercentage: NumStr, holdbackPercentage: NumStr, maxUtilizationPercentage: NumStr, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
204
+ atomicSetEmberShareWhitelist(vaultId: string, shareVaultId: string, whitelisted: boolean, feePercentage: NumStr, maxCapacityPercentage: NumStr, holdbackPercentage: NumStr, maxUtilizationPercentage: NumStr, minSwapGross: NumStr, maxHeldValueAbsolute: NumStr, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
200
205
  /**
201
206
  * Set the max utilization percentage of an ember share source vault
202
207
  * @param vaultId The id of the atomic vault
@@ -317,8 +322,11 @@ export declare class VaultAdminCalls extends OnChainCalls {
317
322
  * draining the full position collateral back into the vault balance
318
323
  * @param vaultId The id of the atomic vault
319
324
  * @param lendingProtocolId Object id of the AlphaLend LendingProtocol
325
+ * @param acceptResidual Abandon a dust residual rather than aborting the exit.
326
+ * Only pass true deliberately: the residual is forfeited, and the exit burns the
327
+ * PositionCap that could otherwise reach it.
320
328
  * @param options Optional tx execution params
321
329
  * @returns OnChainCallResponse
322
330
  */
323
- atomicSetStrategyNoneFromAlphalend(vaultId: string, lendingProtocolId: string, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
331
+ atomicSetStrategyNoneFromAlphalend(vaultId: string, lendingProtocolId: string, acceptResidual: boolean, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
324
332
  }
@@ -340,12 +340,17 @@ export class VaultAdminCalls extends OnChainCalls {
340
340
  * @param maxCapacityPercentage The max capacity percentage
341
341
  * @param holdbackPercentage The holdback percentage
342
342
  * @param maxUtilizationPercentage The max utilization percentage
343
+ * @param minSwapGross Minimum gross swap size, in collateral base units. 0 means
344
+ * no floor. Below it `swap_ember_shares` aborts, which is what keeps dust swaps
345
+ * from walking the fee curve for free.
346
+ * @param maxHeldValueAbsolute Absolute ceiling on the collateral value this vault
347
+ * will custody for the source. 0 means no cap — the percentage caps still apply.
343
348
  * @param options Optional tx execution params
344
349
  * @returns OnChainCallResponse
345
350
  */
346
- async atomicSetEmberShareWhitelist(vaultId, shareVaultId, whitelisted, feePercentage, maxCapacityPercentage, holdbackPercentage, maxUtilizationPercentage, options) {
351
+ async atomicSetEmberShareWhitelist(vaultId, shareVaultId, whitelisted, feePercentage, maxCapacityPercentage, holdbackPercentage, maxUtilizationPercentage, minSwapGross, maxHeldValueAbsolute, options) {
347
352
  const txb = options?.txBlock || new TransactionBlock();
348
- this.txBuilder.atomicSetEmberShareWhitelist(vaultId, shareVaultId, whitelisted, feePercentage, maxCapacityPercentage, holdbackPercentage, maxUtilizationPercentage, { ...options, txBlock: txb });
353
+ this.txBuilder.atomicSetEmberShareWhitelist(vaultId, shareVaultId, whitelisted, feePercentage, maxCapacityPercentage, holdbackPercentage, maxUtilizationPercentage, minSwapGross, maxHeldValueAbsolute, { ...options, txBlock: txb });
349
354
  return this.execCall(txb, options);
350
355
  }
351
356
  /**
@@ -537,15 +542,15 @@ export class VaultAdminCalls extends OnChainCalls {
537
542
  * draining the full position collateral back into the vault balance
538
543
  * @param vaultId The id of the atomic vault
539
544
  * @param lendingProtocolId Object id of the AlphaLend LendingProtocol
545
+ * @param acceptResidual Abandon a dust residual rather than aborting the exit.
546
+ * Only pass true deliberately: the residual is forfeited, and the exit burns the
547
+ * PositionCap that could otherwise reach it.
540
548
  * @param options Optional tx execution params
541
549
  * @returns OnChainCallResponse
542
550
  */
543
- async atomicSetStrategyNoneFromAlphalend(vaultId, lendingProtocolId, options) {
551
+ async atomicSetStrategyNoneFromAlphalend(vaultId, lendingProtocolId, acceptResidual, options) {
544
552
  const txb = options?.txBlock || new TransactionBlock();
545
- this.txBuilder.atomicSetStrategyNoneFromAlphalend(vaultId, lendingProtocolId, {
546
- ...options,
547
- txBlock: txb
548
- });
553
+ this.txBuilder.atomicSetStrategyNoneFromAlphalend(vaultId, lendingProtocolId, acceptResidual, { ...options, txBlock: txb });
549
554
  return this.execCall(txb, options);
550
555
  }
551
556
  }
@@ -1,6 +1,6 @@
1
1
  import { bcs } from "@mysten/sui/bcs";
2
2
  import { BcsUpdateVaultStrategyRequest } from "../interfaces/bcs.js";
3
- const unwrapMoveFields = (value) => value?.fields ?? value;
3
+ import { tableIdOf, unwrapMoveFields } from "../utils/common.js";
4
4
  export class Vault {
5
5
  /**
6
6
  * Fetches the vault rate from on-chain
@@ -65,9 +65,7 @@ export class Vault {
65
65
  });
66
66
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
67
  const fields = unwrapMoveFields(objDetails.object?.json);
68
- const accounts = unwrapMoveFields(fields?.accounts);
69
- const accountTableId = unwrapMoveFields(accounts?.id);
70
- const userTable = accountTableId?.id || accounts?.id;
68
+ const userTable = tableIdOf(fields?.accounts);
71
69
  try {
72
70
  const userData = await suiClient.core.getDynamicObjectField({
73
71
  parentId: userTable,
@@ -1,3 +1,23 @@
1
1
  import { BaseClient as SuiClient } from "@mysten/sui/client";
2
2
  import { TransactionBlock } from "@firefly-exchange/library-sui";
3
3
  export declare const getTxBytes: (tx: TransactionBlock, client: SuiClient) => Promise<string>;
4
+ /**
5
+ * Strip the JSON-RPC `{ fields: {...} }` wrapper from a Move value.
6
+ *
7
+ * gRPC returns the fields directly, JSON-RPC nests them one level down, so this
8
+ * makes a read work on either transport.
9
+ */
10
+ export declare const unwrapMoveFields: (value: any) => any;
11
+ /**
12
+ * The object id of a `Table` / `Bag` / `ObjectTable` field, whichever way the
13
+ * transport rendered its `UID`.
14
+ *
15
+ * The two disagree: over gRPC a UID comes back flattened to a string, so the
16
+ * field reads `{ id: "0x...", size: "1" }`, while JSON-RPC keeps the nesting and
17
+ * gives `{ id: { id: "0x..." }, size: "1" }`. Reaching straight for `.id.id`
18
+ * therefore yields `undefined` on gRPC — and because every caller treats a
19
+ * missing table id as "no such table", the read fails CLOSED: a whitelisted
20
+ * source vault reads as not whitelisted, a real share balance reads as zero.
21
+ * Silent, and wrong in the direction that looks like ordinary empty state.
22
+ */
23
+ export declare const tableIdOf: (field: any) => string | undefined;
@@ -2,3 +2,27 @@ import { toBase64 } from "@mysten/sui/utils";
2
2
  export const getTxBytes = async (tx, client) => {
3
3
  return toBase64(await tx.build({ client: client, onlyTransactionKind: false }));
4
4
  };
5
+ /**
6
+ * Strip the JSON-RPC `{ fields: {...} }` wrapper from a Move value.
7
+ *
8
+ * gRPC returns the fields directly, JSON-RPC nests them one level down, so this
9
+ * makes a read work on either transport.
10
+ */
11
+ export const unwrapMoveFields = (value) => value?.fields ?? value;
12
+ /**
13
+ * The object id of a `Table` / `Bag` / `ObjectTable` field, whichever way the
14
+ * transport rendered its `UID`.
15
+ *
16
+ * The two disagree: over gRPC a UID comes back flattened to a string, so the
17
+ * field reads `{ id: "0x...", size: "1" }`, while JSON-RPC keeps the nesting and
18
+ * gives `{ id: { id: "0x..." }, size: "1" }`. Reaching straight for `.id.id`
19
+ * therefore yields `undefined` on gRPC — and because every caller treats a
20
+ * missing table id as "no such table", the read fails CLOSED: a whitelisted
21
+ * source vault reads as not whitelisted, a real share balance reads as zero.
22
+ * Silent, and wrong in the direction that looks like ordinary empty state.
23
+ */
24
+ export const tableIdOf = (field) => {
25
+ const table = unwrapMoveFields(field);
26
+ const id = unwrapMoveFields(table?.id);
27
+ return (typeof id === "string" ? id : id?.id) ?? undefined;
28
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ember-finance/sdk",
3
3
  "description": "Ember Protocol SDK",
4
- "version": "2.14.0",
4
+ "version": "2.15.0",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",
7
7
  "main": "./dist/index.js",