@ember-finance/sdk 2.4.0 → 2.5.0-pre.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.
Files changed (63) hide show
  1. package/dist/src/abis/AtomicLiquidity.json +4050 -0
  2. package/dist/src/abis/ERC20Token.json +2 -2
  3. package/dist/src/abis/EmberETHVault.json +279 -5
  4. package/dist/src/abis/EmberProtocolConfig.json +137 -2
  5. package/dist/src/abis/EmberVault.json +2 -2
  6. package/dist/src/abis/EmberVaultMintBurnOFTAdapter.json +43 -2
  7. package/dist/src/api/v2/apis/vaults-api.d.ts +16 -4
  8. package/dist/src/api/v2/apis/vaults-api.js +21 -7
  9. package/dist/src/api/v2/models/chain-vault-details.d.ts +7 -0
  10. package/dist/src/api/v2/models/evm-atomic-liquidity-lib.d.ts +48 -0
  11. package/dist/src/api/v2/models/evm-atomic-liquidity-lib.js +14 -0
  12. package/dist/src/api/v2/models/evm-atomic-vault.d.ts +102 -0
  13. package/dist/src/api/v2/models/evm-atomic-vault.js +14 -0
  14. package/dist/src/api/v2/models/evm-contracts.d.ts +16 -0
  15. package/dist/src/api/v2/models/fee-multiplier-tier.d.ts +30 -0
  16. package/dist/src/api/v2/models/fee-multiplier-tier.js +14 -0
  17. package/dist/src/api/v2/models/index.d.ts +4 -0
  18. package/dist/src/api/v2/models/index.js +4 -0
  19. package/dist/src/api/v2/models/instant-withdraw-config.d.ts +67 -0
  20. package/dist/src/api/v2/models/instant-withdraw-config.js +14 -0
  21. package/dist/src/api/v2/models/reward-token.d.ts +0 -6
  22. package/dist/src/api/v2/models/vault-detail.d.ts +11 -0
  23. package/dist/src/api/v2/models/vault-detail.js +4 -0
  24. package/dist/src/atomic/instant-withdraw.d.ts +125 -0
  25. package/dist/src/atomic/instant-withdraw.js +122 -0
  26. package/dist/src/ember-vaults.d.ts +2 -1
  27. package/dist/src/evm-vaults/on-chain-calls/atomic-liquidity.d.ts +98 -0
  28. package/dist/src/evm-vaults/on-chain-calls/atomic-liquidity.js +209 -0
  29. package/dist/src/evm-vaults/on-chain-calls/index.d.ts +1 -0
  30. package/dist/src/evm-vaults/on-chain-calls/index.js +1 -0
  31. package/dist/src/evm-vaults/on-chain-calls/operator.d.ts +10 -0
  32. package/dist/src/evm-vaults/on-chain-calls/operator.js +28 -0
  33. package/dist/src/evm-vaults/on-chain-calls/tx-builder.d.ts +103 -0
  34. package/dist/src/evm-vaults/on-chain-calls/tx-builder.js +273 -0
  35. package/dist/src/evm-vaults/on-chain-calls/user.d.ts +50 -0
  36. package/dist/src/evm-vaults/on-chain-calls/user.js +75 -0
  37. package/dist/src/evm-vaults/on-chain-calls/vault-admin.d.ts +48 -0
  38. package/dist/src/evm-vaults/on-chain-calls/vault-admin.js +112 -0
  39. package/dist/src/evm-vaults/on-chain-calls/vault-reader.d.ts +6 -0
  40. package/dist/src/evm-vaults/on-chain-calls/vault-reader.js +9 -0
  41. package/dist/src/evm-vaults/utils/deployment-parser.d.ts +8 -0
  42. package/dist/src/evm-vaults/utils/deployment-parser.js +11 -0
  43. package/dist/src/sui-vaults/interfaces/index.d.ts +15 -0
  44. package/dist/src/sui-vaults/on-chain-calls/admin.d.ts +37 -1
  45. package/dist/src/sui-vaults/on-chain-calls/admin.js +56 -0
  46. package/dist/src/sui-vaults/on-chain-calls/atomic-liquidity.d.ts +62 -0
  47. package/dist/src/sui-vaults/on-chain-calls/atomic-liquidity.js +174 -0
  48. package/dist/src/sui-vaults/on-chain-calls/index.d.ts +1 -0
  49. package/dist/src/sui-vaults/on-chain-calls/index.js +1 -0
  50. package/dist/src/sui-vaults/on-chain-calls/onchain-calls.d.ts +2 -1
  51. package/dist/src/sui-vaults/on-chain-calls/operator.d.ts +129 -1
  52. package/dist/src/sui-vaults/on-chain-calls/operator.js +210 -0
  53. package/dist/src/sui-vaults/on-chain-calls/tx-builder.d.ts +482 -0
  54. package/dist/src/sui-vaults/on-chain-calls/tx-builder.js +1430 -0
  55. package/dist/src/sui-vaults/on-chain-calls/user.d.ts +107 -1
  56. package/dist/src/sui-vaults/on-chain-calls/user.js +190 -0
  57. package/dist/src/sui-vaults/on-chain-calls/vault-admin.d.ts +229 -1
  58. package/dist/src/sui-vaults/on-chain-calls/vault-admin.js +391 -0
  59. package/dist/src/sui-vaults/on-chain-calls/vault.d.ts +2 -1
  60. package/dist/src/sui-vaults/utils/common.d.ts +2 -1
  61. package/dist/src/sui-vaults/utils/deployment-parser.d.ts +12 -0
  62. package/dist/src/sui-vaults/utils/deployment-parser.js +24 -0
  63. package/package.json +3 -2
@@ -27,6 +27,17 @@ export class EVMDeploymentParser {
27
27
  getProtocolConfigAddress() {
28
28
  return this.deployment.contracts?.protocolConfig.proxyAddress;
29
29
  }
30
+ /**
31
+ * Resolves the protocol config that governs a specific vault. Atomic Liquidity vaults can be
32
+ * deployed against their own protocol config (carried per-vault in the deployment), which may
33
+ * differ from the global one; admin ops for an atomic vault MUST route through that config.
34
+ * Falls back to the global protocol config for non-atomic vaults (and atomic vaults that don't
35
+ * specify one).
36
+ */
37
+ getProtocolConfigAddressForVault(vaultAddress) {
38
+ const atomic = Object.values(this.deployment.contracts?.atomicLiquidityVaults ?? {}).find(v => v.proxyAddress?.toLowerCase() === vaultAddress.toLowerCase());
39
+ return atomic?.protocolConfig ?? this.getProtocolConfigAddress();
40
+ }
30
41
  /**
31
42
  * Gets the protocol config implementation address
32
43
  */
@@ -29,6 +29,21 @@ export interface ISuiDeployment {
29
29
  DepositCoinDecimals: number;
30
30
  };
31
31
  };
32
+ AtomicVaults?: {
33
+ [key: string]: {
34
+ Admin?: Address;
35
+ Operator?: Address;
36
+ RateManager?: Address;
37
+ Name: string;
38
+ MaxRateChangePerUpdate?: string;
39
+ FeePercentage?: string;
40
+ MinWithdrawalShares?: string;
41
+ SubAccounts?: Address[];
42
+ ObjectId: Address;
43
+ CollateralCoinType: Address;
44
+ CollateralCoinDecimals: number;
45
+ };
46
+ };
32
47
  }
33
48
  export interface IDeploymentConfig {
34
49
  rpc: string;
@@ -1,6 +1,7 @@
1
+ import { SuiJsonRpcClient as SuiClient } from "@mysten/sui/jsonRpc";
1
2
  import { OnChainCalls } from "./onchain-calls.js";
2
3
  import { ISuiDeployment, IVaultOptionalParams } from "../interfaces/index.js";
3
- import { OnChainCallResponse, Signer, SuiAddress, SuiClient, SuiTransactionBlockResponseOptions } from "@firefly-exchange/library-sui";
4
+ import { OnChainCallResponse, Signer, SuiAddress, SuiTransactionBlockResponseOptions } from "@firefly-exchange/library-sui";
4
5
  import { NumStr } from "@firefly-exchange/library-sui";
5
6
  export declare class AdminCalls extends OnChainCalls {
6
7
  constructor(_network: string, _suiClient: SuiClient, _deployment: ISuiDeployment, _signer?: Signer, _walletAddress?: string);
@@ -85,4 +86,39 @@ export declare class AdminCalls extends OnChainCalls {
85
86
  * @returns OnChainCallResponse
86
87
  */
87
88
  updateMaxRateInterval(maxRateInterval: NumStr, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
89
+ /**
90
+ * Create and execute a create-atomic-vault transaction. Allows admin to
91
+ * create a new atomic liquidity vault on the protocol.
92
+ * @param collateralCoinType The type of the collateral coin (T)
93
+ * @param vaultName Name of the vault
94
+ * @param adminAddress The admin address of the vault
95
+ * @param operatorAddress The operator address of the vault
96
+ * @param rateManagerAddress The rate manager address of the vault
97
+ * @param maxRateChangePerUpdate The maximum rate change per update
98
+ * @param feePercentage The fee percentage
99
+ * @param minWithdrawalShares The minimum withdrawal shares
100
+ * @param rateUpdateInterval The rate update interval
101
+ * @param maxTVL The maximum TVL of the vault
102
+ * @param subAccounts The sub accounts of the vault
103
+ * @param options Optional tx execution params
104
+ * @returns OnChainCallResponse
105
+ */
106
+ createAtomicVault(collateralCoinType: string, vaultName: string, adminAddress: SuiAddress, operatorAddress: SuiAddress, rateManagerAddress: SuiAddress, maxRateChangePerUpdate: NumStr, feePercentage: NumStr, minWithdrawalShares: NumStr, rateUpdateInterval: NumStr, maxTVL: NumStr, subAccounts: SuiAddress[], options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
107
+ /**
108
+ * Change the admin address of an atomic vault
109
+ * @param vaultId The id of the atomic vault
110
+ * @param adminAddress The new admin address
111
+ * @param options Optional tx execution params
112
+ * @returns OnChainCallResponse
113
+ */
114
+ atomicChangeVaultAdmin(vaultId: string, adminAddress: SuiAddress, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
115
+ /**
116
+ * Set / unset a blacklisted account on an atomic vault
117
+ * @param vaultId The id of the atomic vault
118
+ * @param account The account to set the blacklist status for
119
+ * @param status Whether the account should be blacklisted
120
+ * @param options Optional tx execution params
121
+ * @returns OnChainCallResponse
122
+ */
123
+ atomicSetBlacklistedAccount(vaultId: string, account: SuiAddress, status: boolean, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
88
124
  }
@@ -137,4 +137,60 @@ export class AdminCalls extends OnChainCalls {
137
137
  });
138
138
  return this.execCall(txb, options);
139
139
  }
140
+ // ============================================================================
141
+ // Atomic Liquidity Vault (BFE-818) — protocol admin methods
142
+ // ============================================================================
143
+ /**
144
+ * Create and execute a create-atomic-vault transaction. Allows admin to
145
+ * create a new atomic liquidity vault on the protocol.
146
+ * @param collateralCoinType The type of the collateral coin (T)
147
+ * @param vaultName Name of the vault
148
+ * @param adminAddress The admin address of the vault
149
+ * @param operatorAddress The operator address of the vault
150
+ * @param rateManagerAddress The rate manager address of the vault
151
+ * @param maxRateChangePerUpdate The maximum rate change per update
152
+ * @param feePercentage The fee percentage
153
+ * @param minWithdrawalShares The minimum withdrawal shares
154
+ * @param rateUpdateInterval The rate update interval
155
+ * @param maxTVL The maximum TVL of the vault
156
+ * @param subAccounts The sub accounts of the vault
157
+ * @param options Optional tx execution params
158
+ * @returns OnChainCallResponse
159
+ */
160
+ async createAtomicVault(collateralCoinType, vaultName, adminAddress, operatorAddress, rateManagerAddress, maxRateChangePerUpdate, feePercentage, minWithdrawalShares, rateUpdateInterval, maxTVL, subAccounts, options) {
161
+ const txb = options?.txBlock || new TransactionBlock();
162
+ this.txBuilder.createAtomicVault(collateralCoinType, vaultName, adminAddress, operatorAddress, rateManagerAddress, maxRateChangePerUpdate, feePercentage, minWithdrawalShares, rateUpdateInterval, maxTVL, subAccounts, { ...options, txBlock: txb });
163
+ return this.execCall(txb, options);
164
+ }
165
+ /**
166
+ * Change the admin address of an atomic vault
167
+ * @param vaultId The id of the atomic vault
168
+ * @param adminAddress The new admin address
169
+ * @param options Optional tx execution params
170
+ * @returns OnChainCallResponse
171
+ */
172
+ async atomicChangeVaultAdmin(vaultId, adminAddress, options) {
173
+ const txb = options?.txBlock || new TransactionBlock();
174
+ this.txBuilder.atomicChangeVaultAdmin(vaultId, adminAddress, {
175
+ ...options,
176
+ txBlock: txb
177
+ });
178
+ return this.execCall(txb, options);
179
+ }
180
+ /**
181
+ * Set / unset a blacklisted account on an atomic vault
182
+ * @param vaultId The id of the atomic vault
183
+ * @param account The account to set the blacklist status for
184
+ * @param status Whether the account should be blacklisted
185
+ * @param options Optional tx execution params
186
+ * @returns OnChainCallResponse
187
+ */
188
+ async atomicSetBlacklistedAccount(vaultId, account, status, options) {
189
+ const txb = options?.txBlock || new TransactionBlock();
190
+ this.txBuilder.atomicSetBlacklistedAccount(vaultId, account, status, {
191
+ ...options,
192
+ txBlock: txb
193
+ });
194
+ return this.execCall(txb, options);
195
+ }
140
196
  }
@@ -0,0 +1,62 @@
1
+ import { SuiJsonRpcClient as SuiClient } from "@mysten/sui/jsonRpc";
2
+ import { FeeMultiplierTier, InstantWithdrawQuote } from "../../atomic/instant-withdraw.js";
3
+ /**
4
+ * Read-only views + instant-withdraw quotes for the Sui Atomic Liquidity Vault (BET-4111).
5
+ *
6
+ * There is no on-chain preview function and no off-chain view calls on Sui, so this reads
7
+ * the ALV (and source vault) object fields directly and replicates the Move math
8
+ * (`calculate_amount_from_shares`, `get_vault_tvl`, `swap_ember_shares`,
9
+ * `do_instant_withdraw_core`) via the shared chain-agnostic quote core at scale 1e9.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const reader = new SuiAtomicLiquidityReader(suiClient);
14
+ * const q = await reader.previewSwapInstantWithdraw(vaultId, sourceVaultId, 100_000000n, owner);
15
+ * ```
16
+ */
17
+ export declare class SuiAtomicLiquidityReader {
18
+ suiClient: SuiClient;
19
+ constructor(suiClient: SuiClient);
20
+ /** Raw Move fields of the AtomicLiquidityVault object. */
21
+ private vaultFields;
22
+ /**
23
+ * Read a `Table<K, V>` entry value. Table entries are plain dynamic fields, so we
24
+ * resolve the `Field<K,V>` object id via `getDynamicField`, then fetch its json
25
+ * (`{ name, value }`). Returns the unwrapped `value`, or null if absent.
26
+ */
27
+ private readTableValue;
28
+ /** Rate value (1e9) of any vault object (ALV or source EmberVault). */
29
+ private rateValue;
30
+ /** Per-source-share EmberShare config from the `ember_share_configs` table. */
31
+ getEmberShareConfig(vaultId: string, sourceVaultId: string): Promise<{
32
+ whitelisted: boolean;
33
+ feePercentage: bigint;
34
+ holdbackPercentage: bigint;
35
+ maxCapacityPercentage: bigint;
36
+ maxUtilizationPercentage: bigint;
37
+ epochStartedAt: bigint;
38
+ epochUsedAmount: bigint;
39
+ feeMultiplierCurve: FeeMultiplierTier[];
40
+ } | null>;
41
+ /** Caller's ALV (non-transferable) share balance from the `shares` table. */
42
+ shareOf(vaultId: string, account: string): Promise<bigint>;
43
+ /**
44
+ * Live quote for the EmberShare swap-with-holdback "instant withdraw" on Sui.
45
+ * Reads ALV + source vault fields and replicates `swap_ember_shares` math.
46
+ *
47
+ * `currentHeldValue` defaults to 0 (the common case before any swap); pass it when the
48
+ * ALV already custodies source shares. `availableCapacity` (remaining 24h epoch capacity,
49
+ * collateral units) is bfvs-sourced when precise epoch accounting is required — when
50
+ * omitted, only the utilization cap gates `withinCapacity`.
51
+ */
52
+ previewSwapInstantWithdraw(vaultId: string, sourceVaultId: string, shareAmount: bigint, owner: string, opts?: {
53
+ availableCapacity?: bigint;
54
+ currentHeldValue?: bigint;
55
+ userShareBalance?: bigint;
56
+ }): Promise<InstantWithdrawQuote>;
57
+ /**
58
+ * Live quote for the ALV's own plain `instant_withdraw` on Sui (atomic-share holders).
59
+ * `net = gross - fee`, no holdback, capped by `max_instant_withdraw_shares`.
60
+ */
61
+ previewPlainInstantWithdraw(vaultId: string, shareAmount: bigint, owner: string): Promise<InstantWithdrawQuote>;
62
+ }
@@ -0,0 +1,174 @@
1
+ import { bcs } from "@mysten/sui/bcs";
2
+ import { computeSwapQuote, computePlainInstantQuote } from "../../atomic/instant-withdraw.js";
3
+ /** Sui fixed-point scale (1e9) used by the Atomic Liquidity Vault Move math. */
4
+ const SUI_SCALE = 1000000000n;
5
+ const unwrapMoveFields = (value) => value?.fields ?? value;
6
+ const toBig = (v) => v === undefined || v === null ? 0n : BigInt(v);
7
+ /** `math::div(a, b)` = floor(a * scale / b). */
8
+ const divFloor = (a, b) => (b === 0n ? 0n : (a * SUI_SCALE) / b);
9
+ /** `math::div_ceil(a, b)` = ceil(a * scale / b) — used by `calculate_amount_from_shares`. */
10
+ const divCeil = (a, b) => b === 0n ? 0n : (a * SUI_SCALE + (b - 1n)) / b;
11
+ /**
12
+ * Read-only views + instant-withdraw quotes for the Sui Atomic Liquidity Vault (BET-4111).
13
+ *
14
+ * There is no on-chain preview function and no off-chain view calls on Sui, so this reads
15
+ * the ALV (and source vault) object fields directly and replicates the Move math
16
+ * (`calculate_amount_from_shares`, `get_vault_tvl`, `swap_ember_shares`,
17
+ * `do_instant_withdraw_core`) via the shared chain-agnostic quote core at scale 1e9.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const reader = new SuiAtomicLiquidityReader(suiClient);
22
+ * const q = await reader.previewSwapInstantWithdraw(vaultId, sourceVaultId, 100_000000n, owner);
23
+ * ```
24
+ */
25
+ export class SuiAtomicLiquidityReader {
26
+ constructor(suiClient) {
27
+ this.suiClient = suiClient;
28
+ }
29
+ /** Raw Move fields of the AtomicLiquidityVault object. */
30
+ async vaultFields(vaultId) {
31
+ const res = await this.suiClient.core.getObject({
32
+ objectId: vaultId,
33
+ include: { json: true }
34
+ });
35
+ const fields = unwrapMoveFields(res.object?.json);
36
+ if (!fields)
37
+ throw new Error(`Atomic vault ${vaultId} not found`);
38
+ return fields;
39
+ }
40
+ /**
41
+ * Read a `Table<K, V>` entry value. Table entries are plain dynamic fields, so we
42
+ * resolve the `Field<K,V>` object id via `getDynamicField`, then fetch its json
43
+ * (`{ name, value }`). Returns the unwrapped `value`, or null if absent.
44
+ */
45
+ async readTableValue(parentId, nameType, keyAddress) {
46
+ try {
47
+ const df = await this.suiClient.core.getDynamicField({
48
+ parentId,
49
+ name: { type: nameType, bcs: bcs.Address.serialize(keyAddress).toBytes() }
50
+ });
51
+ const fieldId = df?.dynamicField?.fieldId;
52
+ if (!fieldId)
53
+ return null;
54
+ const obj = await this.suiClient.core.getObject({
55
+ objectId: fieldId,
56
+ include: { json: true }
57
+ });
58
+ return unwrapMoveFields(obj.object?.json)?.value;
59
+ }
60
+ catch {
61
+ return null;
62
+ }
63
+ }
64
+ /** Rate value (1e9) of any vault object (ALV or source EmberVault). */
65
+ async rateValue(vaultId) {
66
+ const res = await this.suiClient.core.getObject({
67
+ objectId: vaultId,
68
+ include: { json: true }
69
+ });
70
+ const fields = unwrapMoveFields(res.object?.json);
71
+ return toBig(unwrapMoveFields(fields?.rate)?.value);
72
+ }
73
+ /** Per-source-share EmberShare config from the `ember_share_configs` table. */
74
+ async getEmberShareConfig(vaultId, sourceVaultId) {
75
+ const fields = await this.vaultFields(vaultId);
76
+ const tableId = unwrapMoveFields(fields.ember_share_configs)?.id?.id;
77
+ if (!tableId)
78
+ return null;
79
+ {
80
+ const cfg = unwrapMoveFields(await this.readTableValue(tableId, "0x2::object::ID", sourceVaultId));
81
+ if (!cfg)
82
+ return null;
83
+ const curve = (cfg.fee_multiplier_curve || []).map((t) => {
84
+ const tf = unwrapMoveFields(t);
85
+ return {
86
+ threshold: toBig(tf.threshold),
87
+ multiplier: toBig(tf.multiplier)
88
+ };
89
+ });
90
+ return {
91
+ whitelisted: !!cfg.whitelisted,
92
+ feePercentage: toBig(cfg.fee_percentage),
93
+ holdbackPercentage: toBig(cfg.holdback_percentage),
94
+ maxCapacityPercentage: toBig(cfg.max_capacity_percentage),
95
+ maxUtilizationPercentage: toBig(cfg.max_utilization_percentage),
96
+ epochStartedAt: toBig(cfg.epoch_started_at),
97
+ epochUsedAmount: toBig(cfg.epoch_used_amount),
98
+ feeMultiplierCurve: curve
99
+ };
100
+ }
101
+ }
102
+ /** Caller's ALV (non-transferable) share balance from the `shares` table. */
103
+ async shareOf(vaultId, account) {
104
+ const fields = await this.vaultFields(vaultId);
105
+ const tableId = unwrapMoveFields(fields.shares)?.id?.id;
106
+ if (!tableId)
107
+ return 0n;
108
+ return toBig(await this.readTableValue(tableId, "address", account));
109
+ }
110
+ /**
111
+ * Live quote for the EmberShare swap-with-holdback "instant withdraw" on Sui.
112
+ * Reads ALV + source vault fields and replicates `swap_ember_shares` math.
113
+ *
114
+ * `currentHeldValue` defaults to 0 (the common case before any swap); pass it when the
115
+ * ALV already custodies source shares. `availableCapacity` (remaining 24h epoch capacity,
116
+ * collateral units) is bfvs-sourced when precise epoch accounting is required — when
117
+ * omitted, only the utilization cap gates `withinCapacity`.
118
+ */
119
+ async previewSwapInstantWithdraw(vaultId, sourceVaultId, shareAmount, owner, opts = {}) {
120
+ const fields = await this.vaultFields(vaultId);
121
+ const atomicRate = toBig(unwrapMoveFields(fields.rate)?.value);
122
+ const totalShares = toBig(fields.total_shares);
123
+ const feeWaived = fields.fee_waived_addresses || [];
124
+ const holdbackWaived = fields.holdback_waived_addresses || [];
125
+ const [config, sourceRate] = await Promise.all([
126
+ this.getEmberShareConfig(vaultId, sourceVaultId),
127
+ this.rateValue(sourceVaultId)
128
+ ]);
129
+ if (!config)
130
+ throw new Error(`source vault ${sourceVaultId} not whitelisted`);
131
+ // gross = calculate_amount_from_shares(source, shareAmount) = div_ceil(shares, sourceRate)
132
+ const grossAmount = divCeil(shareAmount, sourceRate);
133
+ // tvl = get_vault_tvl(atomic) = div(total_shares, atomicRate)
134
+ const vaultTotalAssets = divFloor(totalShares, atomicRate);
135
+ return computeSwapQuote({
136
+ scale: SUI_SCALE,
137
+ grossAmount,
138
+ shareAmount,
139
+ userShareBalance: opts.userShareBalance ?? 0n,
140
+ currentHeldValue: opts.currentHeldValue ?? 0n,
141
+ vaultTotalAssets,
142
+ // Default to "epoch capacity not binding" when not supplied; the on-chain
143
+ // swap still enforces it. Pass from bfvs for an exact pre-check.
144
+ availableCapacity: opts.availableCapacity ?? grossAmount,
145
+ config: {
146
+ feePercentage: config.feePercentage,
147
+ holdbackPercentage: config.holdbackPercentage,
148
+ maxUtilizationPercentage: config.maxUtilizationPercentage,
149
+ feeMultiplierCurve: config.feeMultiplierCurve
150
+ },
151
+ feeWaived: feeWaived.includes(owner),
152
+ holdbackWaived: holdbackWaived.includes(owner)
153
+ });
154
+ }
155
+ /**
156
+ * Live quote for the ALV's own plain `instant_withdraw` on Sui (atomic-share holders).
157
+ * `net = gross - fee`, no holdback, capped by `max_instant_withdraw_shares`.
158
+ */
159
+ async previewPlainInstantWithdraw(vaultId, shareAmount, owner) {
160
+ const fields = await this.vaultFields(vaultId);
161
+ const atomicRate = toBig(unwrapMoveFields(fields.rate)?.value);
162
+ const grossAmount = divCeil(shareAmount, atomicRate);
163
+ const userShareBalance = await this.shareOf(vaultId, owner);
164
+ return computePlainInstantQuote({
165
+ scale: SUI_SCALE,
166
+ grossAmount,
167
+ shareAmount,
168
+ userShareBalance,
169
+ instantWithdrawFeePercentage: toBig(fields.instant_withdraw_fee_percentage),
170
+ cumulativeInstantWithdrawShares: toBig(fields.cumulative_instant_withdraw_shares),
171
+ maxInstantWithdrawShares: toBig(fields.max_instant_withdraw_shares)
172
+ });
173
+ }
174
+ }
@@ -4,3 +4,4 @@ export * from "./user.js";
4
4
  export * from "./vault-admin.js";
5
5
  export * from "./operator.js";
6
6
  export * from "./vault.js";
7
+ export * from "./atomic-liquidity.js";
@@ -4,3 +4,4 @@ export * from "./user.js";
4
4
  export * from "./vault-admin.js";
5
5
  export * from "./operator.js";
6
6
  export * from "./vault.js";
7
+ export * from "./atomic-liquidity.js";
@@ -1,4 +1,5 @@
1
- import { DryRunTransactionBlockResponse, OnChainCallResponse, Signer, SuiClient, SuiTransactionBlockResponse, SuiTransactionBlockResponseOptions, TransactionBlock } from "@firefly-exchange/library-sui";
1
+ import { SuiJsonRpcClient as SuiClient } from "@mysten/sui/jsonRpc";
2
+ import { DryRunTransactionBlockResponse, OnChainCallResponse, Signer, SuiTransactionBlockResponse, SuiTransactionBlockResponseOptions, TransactionBlock } from "@firefly-exchange/library-sui";
2
3
  import { Address } from "@firefly-exchange/library-sui";
3
4
  import { SuiDeploymentParser } from "../utils/deployment-parser.js";
4
5
  import { ISuiDeployment, IVaultOptionalParams } from "../interfaces/index.js";
@@ -1,6 +1,7 @@
1
+ import { SuiJsonRpcClient as SuiClient } from "@mysten/sui/jsonRpc";
1
2
  import { OnChainCalls } from "./onchain-calls.js";
2
3
  import { ISuiDeployment, IVaultOptionalParams } from "../interfaces/index.js";
3
- import { OnChainCallResponse, Signer, SuiAddress, SuiClient, SuiTransactionBlockResponseOptions } from "@firefly-exchange/library-sui";
4
+ import { OnChainCallResponse, Signer, SuiAddress, SuiTransactionBlockResponseOptions } from "@firefly-exchange/library-sui";
4
5
  import { NumStr } from "@firefly-exchange/library-sui";
5
6
  export declare class OperatorCalls extends OnChainCalls {
6
7
  constructor(_network: string, _suiClient: SuiClient, _deployment: ISuiDeployment, _signer?: Signer, _walletAddress?: string);
@@ -100,4 +101,131 @@ export declare class OperatorCalls extends OnChainCalls {
100
101
  * @returns OnChainCallResponse
101
102
  */
102
103
  setFeeExemptionList(vaultId: string, user: SuiAddress, status: boolean, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
104
+ /**
105
+ * Process pending withdrawal requests of an atomic vault
106
+ * @param vaultId The id of the atomic vault
107
+ * @param maxRequests The maximum number of withdrawal requests to process
108
+ * @param options Optional tx execution params
109
+ * @returns OnChainCallResponse
110
+ */
111
+ atomicProcessWithdrawalRequests(vaultId: string, maxRequests: NumStr, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
112
+ /**
113
+ * Process pending withdrawal requests of an atomic vault up to a timestamp
114
+ * @param vaultId The id of the atomic vault
115
+ * @param timestamp The timestamp to process withdrawal requests up to
116
+ * @param options Optional tx execution params
117
+ * @returns OnChainCallResponse
118
+ */
119
+ atomicProcessWithdrawalRequestsUpToTimestamp(vaultId: string, timestamp: NumStr, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
120
+ /**
121
+ * Collect the platform fee of an atomic vault
122
+ * @param vaultId The id of the atomic vault
123
+ * @param loss The reported loss amount
124
+ * @param options Optional tx execution params
125
+ * @returns OnChainCallResponse
126
+ */
127
+ atomicCollectPlatformFee(vaultId: string, loss: NumStr, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
128
+ /**
129
+ * Supply collateral from an atomic vault into the Suilend strategy
130
+ * @param vaultId The id of the atomic vault
131
+ * @param poolCoinType The Suilend pool coin type (P)
132
+ * @param lendingMarketId Object id of the Suilend LendingMarket<P>
133
+ * @param amount The amount to supply
134
+ * @param options Optional tx execution params
135
+ * @returns OnChainCallResponse
136
+ */
137
+ atomicSupplyToSuilendStrategy(vaultId: string, poolCoinType: string, lendingMarketId: string, amount: NumStr, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
138
+ /**
139
+ * Supply collateral from an atomic vault into the AlphaLend strategy
140
+ * @param vaultId The id of the atomic vault
141
+ * @param lendingProtocolId Object id of the AlphaLend LendingProtocol
142
+ * @param amount The amount to supply
143
+ * @param options Optional tx execution params
144
+ * @returns OnChainCallResponse
145
+ */
146
+ atomicSupplyToAlphalendStrategy(vaultId: string, lendingProtocolId: string, amount: NumStr, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
147
+ /**
148
+ * Withdraw collateral from the Suilend strategy back into an atomic vault
149
+ * @param vaultId The id of the atomic vault
150
+ * @param poolCoinType The Suilend pool coin type (P)
151
+ * @param lendingMarketId Object id of the Suilend LendingMarket<P>
152
+ * @param amount The amount to withdraw
153
+ * @param options Optional tx execution params
154
+ * @returns OnChainCallResponse
155
+ */
156
+ atomicWithdrawFromSuilendStrategy(vaultId: string, poolCoinType: string, lendingMarketId: string, amount: NumStr, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
157
+ /**
158
+ * Withdraw collateral from the AlphaLend strategy back into an atomic vault
159
+ * @param vaultId The id of the atomic vault
160
+ * @param lendingProtocolId Object id of the AlphaLend LendingProtocol
161
+ * @param amount The amount to withdraw
162
+ * @param options Optional tx execution params
163
+ * @returns OnChainCallResponse
164
+ */
165
+ atomicWithdrawFromAlphalendStrategy(vaultId: string, lendingProtocolId: string, amount: NumStr, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
166
+ /**
167
+ * Supply collateral from an atomic vault to one of its sub accounts
168
+ * @param vaultId The id of the atomic vault
169
+ * @param subAccount The sub account address
170
+ * @param amount The amount to supply
171
+ * @param options Optional tx execution params
172
+ * @returns OnChainCallResponse
173
+ */
174
+ atomicSupplyToSubAccount(vaultId: string, subAccount: string, amount: NumStr, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
175
+ /**
176
+ * Deposit collateral back into an atomic vault from a sub account
177
+ * @param vaultId The id of the atomic vault
178
+ * @param tokenId Object id of the Receiving<Coin<T>> payment to claim
179
+ * @param subAccount The sub account address
180
+ * @param options Optional tx execution params
181
+ * @returns OnChainCallResponse
182
+ */
183
+ atomicDepositFromSubAccount(vaultId: string, tokenId: string, subAccount: string, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
184
+ /**
185
+ * Redeem collected ember shares from an atomic vault against a source vault
186
+ * @param vaultId The id of the atomic vault
187
+ * @param sourceReceiptType The receipt coin type of the source vault (R)
188
+ * @param sourceVaultId Object id of the source Vault<T, R>
189
+ * @param amount The amount of shares to redeem
190
+ * @param options Optional tx execution params
191
+ * @returns OnChainCallResponse
192
+ */
193
+ atomicRedeemCollectedEmberShares(vaultId: string, sourceReceiptType: string, sourceVaultId: string, amount: NumStr, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
194
+ /**
195
+ * Release users' holdback for an ember share source vault
196
+ * @param vaultId The id of the atomic vault
197
+ * @param shareVaultId Id of the source ember share vault
198
+ * @param unwindingPercentage The unwinding percentage
199
+ * @param maxEntries The max entries to process
200
+ * @param options Optional tx execution params
201
+ * @returns OnChainCallResponse
202
+ */
203
+ atomicReleaseUsersHoldback(vaultId: string, shareVaultId: string, unwindingPercentage: NumStr, maxEntries: NumStr, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
204
+ /**
205
+ * Claim received collateral (a Receiving<Coin<T>>) for an atomic vault
206
+ * @param vaultId The id of the atomic vault
207
+ * @param tokenId Object id of the Receiving<Coin<T>> payment to claim
208
+ * @param options Optional tx execution params
209
+ * @returns OnChainCallResponse
210
+ */
211
+ atomicClaimReceivedCollateral(vaultId: string, tokenId: string, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
212
+ /**
213
+ * Claim returned ember shares (a Receiving<Coin<R>>) for an atomic vault
214
+ * @param vaultId The id of the atomic vault
215
+ * @param sourceReceiptType The receipt coin type of the source vault (R)
216
+ * @param sourceVaultId Id of the source vault the shares belong to
217
+ * @param tokenId Object id of the Receiving<Coin<R>> payment to claim
218
+ * @param options Optional tx execution params
219
+ * @returns OnChainCallResponse
220
+ */
221
+ atomicClaimReturnedEmberShares(vaultId: string, sourceReceiptType: string, sourceVaultId: string, tokenId: string, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
222
+ /**
223
+ * Update the rate of an atomic vault (rate manager role; uses operator class
224
+ * to mirror the receipt-vault `updateVaultRate` placement)
225
+ * @param vaultId The id of the atomic vault
226
+ * @param newRate The new rate to set for the vault
227
+ * @param options Optional tx execution params
228
+ * @returns OnChainCallResponse
229
+ */
230
+ atomicUpdateVaultRate(vaultId: string, newRate: NumStr, options?: IVaultOptionalParams & SuiTransactionBlockResponseOptions): Promise<OnChainCallResponse>;
103
231
  }