@ember-finance/sdk 2.3.1 → 2.5.0-pre.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.
Files changed (58) 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/vault-detail.d.ts +11 -0
  22. package/dist/src/api/v2/models/vault-detail.js +4 -0
  23. package/dist/src/atomic/instant-withdraw.d.ts +125 -0
  24. package/dist/src/atomic/instant-withdraw.js +122 -0
  25. package/dist/src/evm-vaults/on-chain-calls/atomic-liquidity.d.ts +98 -0
  26. package/dist/src/evm-vaults/on-chain-calls/atomic-liquidity.js +209 -0
  27. package/dist/src/evm-vaults/on-chain-calls/index.d.ts +1 -0
  28. package/dist/src/evm-vaults/on-chain-calls/index.js +1 -0
  29. package/dist/src/evm-vaults/on-chain-calls/operator.d.ts +10 -0
  30. package/dist/src/evm-vaults/on-chain-calls/operator.js +28 -0
  31. package/dist/src/evm-vaults/on-chain-calls/tx-builder.d.ts +103 -0
  32. package/dist/src/evm-vaults/on-chain-calls/tx-builder.js +273 -0
  33. package/dist/src/evm-vaults/on-chain-calls/user.d.ts +50 -0
  34. package/dist/src/evm-vaults/on-chain-calls/user.js +75 -0
  35. package/dist/src/evm-vaults/on-chain-calls/vault-admin.d.ts +48 -0
  36. package/dist/src/evm-vaults/on-chain-calls/vault-admin.js +112 -0
  37. package/dist/src/evm-vaults/on-chain-calls/vault-reader.d.ts +6 -0
  38. package/dist/src/evm-vaults/on-chain-calls/vault-reader.js +9 -0
  39. package/dist/src/evm-vaults/utils/deployment-parser.d.ts +8 -0
  40. package/dist/src/evm-vaults/utils/deployment-parser.js +11 -0
  41. package/dist/src/sui-vaults/interfaces/index.d.ts +15 -0
  42. package/dist/src/sui-vaults/on-chain-calls/admin.d.ts +35 -0
  43. package/dist/src/sui-vaults/on-chain-calls/admin.js +56 -0
  44. package/dist/src/sui-vaults/on-chain-calls/atomic-liquidity.d.ts +62 -0
  45. package/dist/src/sui-vaults/on-chain-calls/atomic-liquidity.js +174 -0
  46. package/dist/src/sui-vaults/on-chain-calls/index.d.ts +1 -0
  47. package/dist/src/sui-vaults/on-chain-calls/index.js +1 -0
  48. package/dist/src/sui-vaults/on-chain-calls/operator.d.ts +127 -0
  49. package/dist/src/sui-vaults/on-chain-calls/operator.js +210 -0
  50. package/dist/src/sui-vaults/on-chain-calls/tx-builder.d.ts +482 -0
  51. package/dist/src/sui-vaults/on-chain-calls/tx-builder.js +1430 -0
  52. package/dist/src/sui-vaults/on-chain-calls/user.d.ts +105 -0
  53. package/dist/src/sui-vaults/on-chain-calls/user.js +190 -0
  54. package/dist/src/sui-vaults/on-chain-calls/vault-admin.d.ts +228 -1
  55. package/dist/src/sui-vaults/on-chain-calls/vault-admin.js +391 -0
  56. package/dist/src/sui-vaults/utils/deployment-parser.d.ts +12 -0
  57. package/dist/src/sui-vaults/utils/deployment-parser.js +24 -0
  58. package/package.json +3 -2
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Ember Protocol Vaults API
3
+ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
4
+ *
5
+ * The version of the OpenAPI document: 2.0.0
6
+ *
7
+ *
8
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
+ * https://openapi-generator.tech
10
+ * Do not edit the class manually.
11
+ */
12
+ /**
13
+ *
14
+ * @export
15
+ * @interface FeeMultiplierTier
16
+ */
17
+ export interface FeeMultiplierTier {
18
+ /**
19
+ * Utilization threshold (fixed-point, 1e18 EVM / 1e9 Sui)
20
+ * @type {string}
21
+ * @memberof FeeMultiplierTier
22
+ */
23
+ threshold: string;
24
+ /**
25
+ * Fee multiplier at/above the threshold (fixed-point, 1x = scale)
26
+ * @type {string}
27
+ * @memberof FeeMultiplierTier
28
+ */
29
+ multiplier: string;
30
+ }
@@ -0,0 +1,14 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * Ember Protocol Vaults API
5
+ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6
+ *
7
+ * The version of the OpenAPI document: 2.0.0
8
+ *
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+ export {};
@@ -18,6 +18,8 @@ export * from "./coin-price.js";
18
18
  export * from "./defi-integration.js";
19
19
  export * from "./deposit-transaction.js";
20
20
  export * from "./ember-position.js";
21
+ export * from "./evm-atomic-liquidity-lib.js";
22
+ export * from "./evm-atomic-vault.js";
21
23
  export * from "./evm-contracts.js";
22
24
  export * from "./evm-deposit-parking-lot.js";
23
25
  export * from "./evm-deposit-token.js";
@@ -34,8 +36,10 @@ export * from "./exposure.js";
34
36
  export * from "./exposure-coin.js";
35
37
  export * from "./exposure-protocol.js";
36
38
  export * from "./fee.js";
39
+ export * from "./fee-multiplier-tier.js";
37
40
  export * from "./fees.js";
38
41
  export * from "./history-interval.js";
42
+ export * from "./instant-withdraw-config.js";
39
43
  export * from "./lp.js";
40
44
  export * from "./manager.js";
41
45
  export * from "./min-withdrawal-shares-updated-event.js";
@@ -18,6 +18,8 @@ export * from "./coin-price.js";
18
18
  export * from "./defi-integration.js";
19
19
  export * from "./deposit-transaction.js";
20
20
  export * from "./ember-position.js";
21
+ export * from "./evm-atomic-liquidity-lib.js";
22
+ export * from "./evm-atomic-vault.js";
21
23
  export * from "./evm-contracts.js";
22
24
  export * from "./evm-deposit-parking-lot.js";
23
25
  export * from "./evm-deposit-token.js";
@@ -34,8 +36,10 @@ export * from "./exposure.js";
34
36
  export * from "./exposure-coin.js";
35
37
  export * from "./exposure-protocol.js";
36
38
  export * from "./fee.js";
39
+ export * from "./fee-multiplier-tier.js";
37
40
  export * from "./fees.js";
38
41
  export * from "./history-interval.js";
42
+ export * from "./instant-withdraw-config.js";
39
43
  export * from "./lp.js";
40
44
  export * from "./manager.js";
41
45
  export * from "./min-withdrawal-shares-updated-event.js";
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Ember Protocol Vaults API
3
+ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
4
+ *
5
+ * The version of the OpenAPI document: 2.0.0
6
+ *
7
+ *
8
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
+ * https://openapi-generator.tech
10
+ * Do not edit the class manually.
11
+ */
12
+ import type { FeeMultiplierTier } from "./fee-multiplier-tier.js";
13
+ /**
14
+ *
15
+ * @export
16
+ * @interface InstantWithdrawConfig
17
+ */
18
+ export interface InstantWithdrawConfig {
19
+ /**
20
+ * On-chain id of the whitelisted source vault
21
+ * @type {string}
22
+ * @memberof InstantWithdrawConfig
23
+ */
24
+ sourceVaultId: string;
25
+ /**
26
+ * Stable off-chain id of the source vault (null when the source vault is not indexed by us, e.g. an external EmberShare)
27
+ * @type {string}
28
+ * @memberof InstantWithdrawConfig
29
+ */
30
+ sourceVaultOffchainId?: string | null;
31
+ /**
32
+ *
33
+ * @type {boolean}
34
+ * @memberof InstantWithdrawConfig
35
+ */
36
+ whitelisted: boolean;
37
+ /**
38
+ * Base instant-withdraw fee (1e18 fixed-point)
39
+ * @type {string}
40
+ * @memberof InstantWithdrawConfig
41
+ */
42
+ feePercentageE18: string;
43
+ /**
44
+ * Portion held back and released later (1e18 fixed-point)
45
+ * @type {string}
46
+ * @memberof InstantWithdrawConfig
47
+ */
48
+ holdbackPercentageE18: string;
49
+ /**
50
+ * Max swap capacity per epoch as a % of source vault TVL (1e18 fixed-point)
51
+ * @type {string}
52
+ * @memberof InstantWithdrawConfig
53
+ */
54
+ maxCapacityPercentageE18: string;
55
+ /**
56
+ * Post-swap concentration cap (1e18 fixed-point)
57
+ * @type {string}
58
+ * @memberof InstantWithdrawConfig
59
+ */
60
+ maxUtilizationPercentageE18: string;
61
+ /**
62
+ *
63
+ * @type {Array<FeeMultiplierTier>}
64
+ * @memberof InstantWithdrawConfig
65
+ */
66
+ feeMultiplierCurve: Array<FeeMultiplierTier>;
67
+ }
@@ -0,0 +1,14 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * Ember Protocol Vaults API
5
+ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6
+ *
7
+ * The version of the OpenAPI document: 2.0.0
8
+ *
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+ export {};
@@ -30,6 +30,12 @@ export interface VaultDetail {
30
30
  * @memberof VaultDetail
31
31
  */
32
32
  id: string;
33
+ /**
34
+ * Vault flavor at the parent (root) level. TOKENIZED vaults mint a transferable receipt token. ATOMIC (atomic-liquidity) vaults use non-transferable internal shares and have no real receipt token. Defaults to TOKENIZED for backward compatibility.
35
+ * @type {string}
36
+ * @memberof VaultDetail
37
+ */
38
+ vaultType?: VaultDetailVaultTypeEnum;
33
39
  /**
34
40
  * Short name/symbol of the vault
35
41
  * @type {string}
@@ -237,6 +243,11 @@ export interface VaultDetail {
237
243
  */
238
244
  defiIntegrations: Array<DefiIntegration>;
239
245
  }
246
+ export declare const VaultDetailVaultTypeEnum: {
247
+ readonly Tokenized: "TOKENIZED";
248
+ readonly Atomic: "ATOMIC";
249
+ };
250
+ export type VaultDetailVaultTypeEnum = (typeof VaultDetailVaultTypeEnum)[keyof typeof VaultDetailVaultTypeEnum];
240
251
  export declare const VaultDetailStatusEnum: {
241
252
  readonly Active: "active";
242
253
  readonly Paused: "paused";
@@ -11,6 +11,10 @@
11
11
  * https://openapi-generator.tech
12
12
  * Do not edit the class manually.
13
13
  */
14
+ export const VaultDetailVaultTypeEnum = {
15
+ Tokenized: "TOKENIZED",
16
+ Atomic: "ATOMIC"
17
+ };
14
18
  export const VaultDetailStatusEnum = {
15
19
  Active: "active",
16
20
  Paused: "paused",
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Chain-agnostic Atomic Liquidity Vault (ALV) instant-withdraw quote core (BET-4111).
3
+ *
4
+ * There is NO on-chain preview/quote function on the ALV, so the SDK computes the
5
+ * quote client-side by mirroring the exact contract math. Both chains use the same
6
+ * formulas with a different fixed-point scale, so this module is parameterised by
7
+ * `scale` (EVM = 1e18, Sui = 1e9) and consumed by both the EVM and Sui readers, which
8
+ * supply the live on-chain inputs (rate/TVL/held-value/config) via RPC.
9
+ *
10
+ * Mirrors:
11
+ * - swap-with-holdback: EVM `AtomicLiquidityLib.swapEmberShares`,
12
+ * Sui `atomic_liquidity_vault::swap_ember_shares`
13
+ * - plain instant withdraw: EVM `AtomicLiquidity.instantWithdraw`,
14
+ * Sui `do_instant_withdraw_core`
15
+ * - fixed point: `Math.mul = (a*b)/scale`, `Math.div = (a*scale)/b` (floor)
16
+ * - fee curve: `_lookupFeeMultiplier` (ascending tiers; highest threshold <= utilization wins; 1x default)
17
+ */
18
+ /** Fixed-point multiply: `(a * b) / scale`, floor (matches Solidity/Move `Math.mul`). */
19
+ export declare function mulFp(a: bigint, b: bigint, scale: bigint): bigint;
20
+ /** Fixed-point divide: `(a * scale) / b`, floor (matches Solidity/Move `Math.div`). */
21
+ export declare function divFp(a: bigint, b: bigint, scale: bigint): bigint;
22
+ /** A single (threshold, multiplier) tier of the fee-multiplier curve (fixed-point at `scale`). */
23
+ export interface FeeMultiplierTier {
24
+ threshold: bigint;
25
+ multiplier: bigint;
26
+ }
27
+ /**
28
+ * Resolve the fee multiplier from an ascending curve at a given utilization.
29
+ * Returns the multiplier of the highest tier whose `threshold <= utilization`, or `scale`
30
+ * (1x) when the curve is empty / no tier matches. Mirrors `_lookupFeeMultiplier`.
31
+ */
32
+ export declare function lookupFeeMultiplier(curve: FeeMultiplierTier[], utilization: bigint, scale: bigint): bigint;
33
+ /** Per-source-share EmberShare swap config (fixed-point percentages at `scale`). */
34
+ export interface EmberShareSwapConfig {
35
+ feePercentage: bigint;
36
+ holdbackPercentage: bigint;
37
+ maxUtilizationPercentage: bigint;
38
+ feeMultiplierCurve: FeeMultiplierTier[];
39
+ /**
40
+ * Minimum gross collateral value per swap (collateral units). A swap with
41
+ * `gross < minSwapGross` reverts `SwapAmountTooSmall`. 0/undefined disables the floor.
42
+ * EVM-only (no Sui equivalent yet) — omit on Sui.
43
+ */
44
+ minSwapGross?: bigint;
45
+ /**
46
+ * TVL-independent absolute ceiling on this source share's post-swap held value
47
+ * (collateral units). A swap pushing `currentHeldValue + gross` above it reverts
48
+ * `EmberShareHeldValueCapExceeded`. 0/undefined disables it. EVM-only — omit on Sui.
49
+ */
50
+ maxHeldValueAbsolute?: bigint;
51
+ }
52
+ export interface SwapQuoteInputs {
53
+ /** Fixed-point scale: 1e18 (EVM) / 1e9 (Sui). */
54
+ scale: bigint;
55
+ /** Gross collateral value of the source shares: `source.convertToAssets(shareAmount)`. */
56
+ grossAmount: bigint;
57
+ /** Source shares being swapped (for `resultingShares`). */
58
+ shareAmount: bigint;
59
+ /** Caller's current source-share balance (for `resultingShares`). */
60
+ userShareBalance: bigint;
61
+ /** Collateral value the ALV already holds for this source share (pre-swap). */
62
+ currentHeldValue: bigint;
63
+ /** ALV `totalAssets()`. */
64
+ vaultTotalAssets: bigint;
65
+ /** Remaining epoch capacity for this source share: `availableEmberShareCapacity(share)`. */
66
+ availableCapacity: bigint;
67
+ config: EmberShareSwapConfig;
68
+ feeWaived?: boolean;
69
+ holdbackWaived?: boolean;
70
+ }
71
+ export interface InstantWithdrawQuote {
72
+ /** Gross collateral value of the redeemed shares. */
73
+ grossAmount: bigint;
74
+ /** Paid to the receiver immediately (`gross - fee - holdback`). */
75
+ instantlyReceive: bigint;
76
+ /** Held back, released later by the operator (0 for the plain path). */
77
+ lockedAmount: bigint;
78
+ /** Fee charged (collateral units). */
79
+ feeAmount: bigint;
80
+ /** Effective fee % applied (base * curve multiplier), fixed-point at `scale`. */
81
+ effectiveFeePercentage: bigint;
82
+ /** Holdback % applied, fixed-point at `scale` (0 for the plain path). */
83
+ holdbackPercentage: bigint;
84
+ /** Post-swap utilization used for the cap + fee-multiplier (0 for the plain path). */
85
+ utilizationAtSwap: bigint;
86
+ /** Caller's source-share balance after the withdraw. */
87
+ resultingShares: bigint;
88
+ /** True if the swap/withdraw would succeed against ALL caps (utilization, epoch capacity,
89
+ * absolute held-value, min-swap floor). Use the granular flags below to explain a `false`. */
90
+ withinCapacity: boolean;
91
+ /** True if `gross < minSwapGross` — the swap would revert `SwapAmountTooSmall`.
92
+ * Always false for the plain path and when no floor is configured. */
93
+ belowMinSwap: boolean;
94
+ /** True if the post-swap held value is within `maxHeldValueAbsolute` (or the cap is disabled).
95
+ * Always true for the plain path. */
96
+ withinHeldValueCap: boolean;
97
+ }
98
+ /**
99
+ * Quote the EmberShare swap-with-holdback path (source tokenized vault -> ALV).
100
+ * Mirrors `swapEmberShares` exactly: post-swap utilization drives the fee multiplier,
101
+ * `net = gross - fee - holdback` is paid now, the holdback is queued for later release.
102
+ */
103
+ export declare function computeSwapQuote(inputs: SwapQuoteInputs): InstantWithdrawQuote;
104
+ export interface PlainInstantQuoteInputs {
105
+ /** Fixed-point scale: 1e18 (EVM) / 1e9 (Sui). */
106
+ scale: bigint;
107
+ /** Gross collateral value of the shares: ALV `convertToAssets(shareAmount)`. */
108
+ grossAmount: bigint;
109
+ /** ALV shares being instantly withdrawn. */
110
+ shareAmount: bigint;
111
+ /** Caller's current ALV share balance (for `resultingShares`). */
112
+ userShareBalance: bigint;
113
+ /** `instantWithdrawFeePercentage`, fixed-point at `scale`. */
114
+ instantWithdrawFeePercentage: bigint;
115
+ /** `cumulativeInstantWithdrawShares`. */
116
+ cumulativeInstantWithdrawShares: bigint;
117
+ /** `maxInstantWithdrawShares` (cumulative cap). */
118
+ maxInstantWithdrawShares: bigint;
119
+ }
120
+ /**
121
+ * Quote the ALV's own plain `instantWithdraw` path (atomic-share holders).
122
+ * Mirrors the contract: `net = gross - fee`, no holdback; capped by
123
+ * `cumulative + shares <= maxInstantWithdrawShares`.
124
+ */
125
+ export declare function computePlainInstantQuote(inputs: PlainInstantQuoteInputs): InstantWithdrawQuote;
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Chain-agnostic Atomic Liquidity Vault (ALV) instant-withdraw quote core (BET-4111).
3
+ *
4
+ * There is NO on-chain preview/quote function on the ALV, so the SDK computes the
5
+ * quote client-side by mirroring the exact contract math. Both chains use the same
6
+ * formulas with a different fixed-point scale, so this module is parameterised by
7
+ * `scale` (EVM = 1e18, Sui = 1e9) and consumed by both the EVM and Sui readers, which
8
+ * supply the live on-chain inputs (rate/TVL/held-value/config) via RPC.
9
+ *
10
+ * Mirrors:
11
+ * - swap-with-holdback: EVM `AtomicLiquidityLib.swapEmberShares`,
12
+ * Sui `atomic_liquidity_vault::swap_ember_shares`
13
+ * - plain instant withdraw: EVM `AtomicLiquidity.instantWithdraw`,
14
+ * Sui `do_instant_withdraw_core`
15
+ * - fixed point: `Math.mul = (a*b)/scale`, `Math.div = (a*scale)/b` (floor)
16
+ * - fee curve: `_lookupFeeMultiplier` (ascending tiers; highest threshold <= utilization wins; 1x default)
17
+ */
18
+ /** Fixed-point multiply: `(a * b) / scale`, floor (matches Solidity/Move `Math.mul`). */
19
+ export function mulFp(a, b, scale) {
20
+ if (a === 0n || b === 0n)
21
+ return 0n;
22
+ return (a * b) / scale;
23
+ }
24
+ /** Fixed-point divide: `(a * scale) / b`, floor (matches Solidity/Move `Math.div`). */
25
+ export function divFp(a, b, scale) {
26
+ if (b === 0n)
27
+ return 0n;
28
+ return (a * scale) / b;
29
+ }
30
+ /**
31
+ * Resolve the fee multiplier from an ascending curve at a given utilization.
32
+ * Returns the multiplier of the highest tier whose `threshold <= utilization`, or `scale`
33
+ * (1x) when the curve is empty / no tier matches. Mirrors `_lookupFeeMultiplier`.
34
+ */
35
+ export function lookupFeeMultiplier(curve, utilization, scale) {
36
+ let multiplier = scale; // 1x
37
+ for (const tier of curve) {
38
+ if (utilization >= tier.threshold) {
39
+ multiplier = tier.multiplier;
40
+ }
41
+ else {
42
+ break; // ascending: once utilization < threshold, all later tiers are higher
43
+ }
44
+ }
45
+ return multiplier;
46
+ }
47
+ /**
48
+ * Quote the EmberShare swap-with-holdback path (source tokenized vault -> ALV).
49
+ * Mirrors `swapEmberShares` exactly: post-swap utilization drives the fee multiplier,
50
+ * `net = gross - fee - holdback` is paid now, the holdback is queued for later release.
51
+ */
52
+ export function computeSwapQuote(inputs) {
53
+ const { scale, grossAmount, config, feeWaived, holdbackWaived } = inputs;
54
+ const newHeldValue = inputs.currentHeldValue + grossAmount;
55
+ const utilizationAtSwap = inputs.vaultTotalAssets === 0n
56
+ ? 0n
57
+ : divFp(newHeldValue, inputs.vaultTotalAssets, scale);
58
+ const feeMultiplier = lookupFeeMultiplier(config.feeMultiplierCurve, utilizationAtSwap, scale);
59
+ const effectiveFeePercentage = mulFp(config.feePercentage, feeMultiplier, scale);
60
+ const feeAmount = feeWaived ? 0n : mulFp(grossAmount, effectiveFeePercentage, scale);
61
+ const holdbackAmount = holdbackWaived
62
+ ? 0n
63
+ : mulFp(grossAmount, config.holdbackPercentage, scale);
64
+ // Mirror the contract's underflow guard.
65
+ const instantlyReceive = feeAmount + holdbackAmount > grossAmount
66
+ ? 0n
67
+ : grossAmount - feeAmount - holdbackAmount;
68
+ const withinUtilization = utilizationAtSwap <= config.maxUtilizationPercentage;
69
+ const withinEpochCapacity = grossAmount <= inputs.availableCapacity;
70
+ // Absolute held-value cap (0/undefined disables it); mirrors EmberShareHeldValueCapExceeded.
71
+ const maxHeldValueAbsolute = config.maxHeldValueAbsolute ?? 0n;
72
+ const withinHeldValueCap = maxHeldValueAbsolute === 0n || newHeldValue <= maxHeldValueAbsolute;
73
+ // Per-swap dust floor (0/undefined disables it); mirrors SwapAmountTooSmall.
74
+ const minSwapGross = config.minSwapGross ?? 0n;
75
+ const belowMinSwap = minSwapGross > 0n && grossAmount < minSwapGross;
76
+ return {
77
+ grossAmount,
78
+ instantlyReceive,
79
+ lockedAmount: holdbackAmount,
80
+ feeAmount,
81
+ effectiveFeePercentage,
82
+ holdbackPercentage: holdbackWaived ? 0n : config.holdbackPercentage,
83
+ utilizationAtSwap,
84
+ resultingShares: inputs.userShareBalance >= inputs.shareAmount
85
+ ? inputs.userShareBalance - inputs.shareAmount
86
+ : 0n,
87
+ belowMinSwap,
88
+ withinHeldValueCap,
89
+ withinCapacity: withinUtilization &&
90
+ withinEpochCapacity &&
91
+ withinHeldValueCap &&
92
+ !belowMinSwap &&
93
+ feeAmount + holdbackAmount <= grossAmount
94
+ };
95
+ }
96
+ /**
97
+ * Quote the ALV's own plain `instantWithdraw` path (atomic-share holders).
98
+ * Mirrors the contract: `net = gross - fee`, no holdback; capped by
99
+ * `cumulative + shares <= maxInstantWithdrawShares`.
100
+ */
101
+ export function computePlainInstantQuote(inputs) {
102
+ const { scale, grossAmount, shareAmount } = inputs;
103
+ const feeAmount = mulFp(grossAmount, inputs.instantWithdrawFeePercentage, scale);
104
+ const instantlyReceive = feeAmount > grossAmount ? 0n : grossAmount - feeAmount;
105
+ const withinCapacity = inputs.cumulativeInstantWithdrawShares + shareAmount <=
106
+ inputs.maxInstantWithdrawShares;
107
+ return {
108
+ grossAmount,
109
+ instantlyReceive,
110
+ lockedAmount: 0n,
111
+ feeAmount,
112
+ effectiveFeePercentage: inputs.instantWithdrawFeePercentage,
113
+ holdbackPercentage: 0n,
114
+ utilizationAtSwap: 0n,
115
+ resultingShares: inputs.userShareBalance >= shareAmount
116
+ ? inputs.userShareBalance - shareAmount
117
+ : 0n,
118
+ belowMinSwap: false,
119
+ withinHeldValueCap: true,
120
+ withinCapacity
121
+ };
122
+ }
@@ -0,0 +1,98 @@
1
+ import { Provider } from "ethers";
2
+ import { FeeMultiplierTier, InstantWithdrawQuote } from "../../atomic/instant-withdraw.js";
3
+ /**
4
+ * Read-only views for the Atomic Liquidity Vault (BFE-817/818).
5
+ *
6
+ * Write calls live on the role classes (EVMUserCalls.instantWithdraw /
7
+ * swapEmberShares, EVMOperatorCalls.supplyToStrategy / withdrawFromStrategy /
8
+ * redeemCollectedEmberShares / releaseUsersHoldback, EVMVaultAdminCalls.setStrategy /
9
+ * setEmberShareWhitelist / setSwapWaiver / setMaxInstantWithdrawShares /
10
+ * setInstantWithdrawFeePercentage). Shared lifecycle calls (deposit, redeemShares,
11
+ * cancelPendingWithdrawalRequest, processWithdrawalRequests, collectPlatformFee,
12
+ * updateVaultRate, pause/role/cap setters) reuse the existing EmberVault methods on
13
+ * those same classes.
14
+ *
15
+ * This reader uses an ethers Contract against the bundled AtomicLiquidity ABI and
16
+ * provides typed convenience getters plus a generic `read` for any view not covered.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const reader = new EVMAtomicLiquidityReader(provider);
21
+ * const rate = await reader.rate(vault);
22
+ * const supplied = await reader.getStrategyAssets(vault);
23
+ * const cfg = await reader.read(vault, "emberShareConfigs", [sourceShare]);
24
+ * ```
25
+ */
26
+ export declare class EVMAtomicLiquidityReader {
27
+ provider: Provider;
28
+ constructor(_provider: Provider);
29
+ private contract;
30
+ /** A source EmberShare vault (ERC-4626) for read-only convertToAssets/balanceOf/accounts. */
31
+ private shareContract;
32
+ /** Generic view call for any function on the AtomicLiquidity ABI. */
33
+ read(vaultAddress: string, functionName: string, args?: unknown[]): Promise<unknown>;
34
+ /** roles() -> { admin, operator, rateManager }. */
35
+ roles(vaultAddress: string): Promise<unknown>;
36
+ /** rate() -> { value, maxRateChangePerUpdate, rateUpdateInterval, lastUpdatedAt }. */
37
+ rate(vaultAddress: string): Promise<unknown>;
38
+ /** Current external strategy address (zero if none). */
39
+ strategy(vaultAddress: string): Promise<string>;
40
+ /** Assets currently supplied to the strategy. */
41
+ getStrategyAssets(vaultAddress: string): Promise<bigint>;
42
+ /** Total assets (idle + strategy + outstanding). */
43
+ totalAssets(vaultAddress: string): Promise<bigint>;
44
+ /**
45
+ * Solvency margin (collateral units, signed): `totalAssets - totalLiabilities`. Negative
46
+ * means the vault is under-collateralised. Monitoring view added with the audit fixes.
47
+ */
48
+ solvencyMargin(vaultAddress: string): Promise<bigint>;
49
+ /** Total non-transferable shares in circulation. */
50
+ totalShares(vaultAddress: string): Promise<bigint>;
51
+ /** Non-transferable share balance of `account`. */
52
+ shareOf(vaultAddress: string, account: string): Promise<bigint>;
53
+ /** Cumulative instant-withdraw shares used. */
54
+ cumulativeInstantWithdrawShares(vaultAddress: string): Promise<bigint>;
55
+ /** Configured instant-withdraw cap (shares). */
56
+ maxInstantWithdrawShares(vaultAddress: string): Promise<bigint>;
57
+ /** Remaining instant-withdraw headroom (shares). */
58
+ availableInstantWithdrawShares(vaultAddress: string): Promise<bigint>;
59
+ /** Per-source-share swap config. */
60
+ emberShareConfigs(vaultAddress: string, share: string): Promise<unknown>;
61
+ /** Remaining swap capacity for a source share in the current epoch. */
62
+ availableEmberShareCapacity(vaultAddress: string, share: string): Promise<bigint>;
63
+ /** Length of the holdback FIFO for a source share. */
64
+ getHoldbackQueueLength(vaultAddress: string, share: string): Promise<bigint>;
65
+ /**
66
+ * Escrowed (deferred) holdback collateral claimable by `account` — accrued when a
67
+ * holdback payout couldn't be transferred to it during `releaseUsersHoldback` (e.g. a
68
+ * token-level blocklist). Claim via user `claimHoldback` / `claimHoldbackFor`. 0 if none.
69
+ */
70
+ unclaimedHoldback(vaultAddress: string, account: string): Promise<bigint>;
71
+ /** Whether `operation` ("deposits" | "withdrawals" | "privilegedOperations") is paused. */
72
+ pauseStatus(vaultAddress: string, operation: string): Promise<boolean>;
73
+ /** Per-account state (shares + pending withdrawals). */
74
+ getAccountState(vaultAddress: string, account: string): Promise<unknown>;
75
+ /** Convert a share amount to assets at the current rate. */
76
+ convertToAssets(vaultAddress: string, shares: bigint): Promise<bigint>;
77
+ /** Convert an asset amount to shares at the current rate. */
78
+ convertToShares(vaultAddress: string, assets: bigint): Promise<bigint>;
79
+ /** Contract version string. */
80
+ version(vaultAddress: string): Promise<string>;
81
+ /**
82
+ * Live quote for the EmberShare swap-with-holdback "instant withdraw": a holder of a
83
+ * source vault's shares (`share`) swaps `shareAmount` into this ALV, receiving most of
84
+ * the value instantly with a small % held back for later operator release.
85
+ *
86
+ * All dynamic inputs (rate, TVL, held value, epoch capacity, waivers) are read live via
87
+ * RPC. The fee-multiplier curve has no on-chain getter (the public `emberShareConfigs`
88
+ * getter omits the dynamic array), so pass it from bfvs `instantWithdrawConfig`; an empty
89
+ * curve means a 1x multiplier (matches the contract default).
90
+ */
91
+ previewSwapInstantWithdraw(vaultAddress: string, share: string, shareAmount: bigint, owner: string, feeMultiplierCurve?: FeeMultiplierTier[]): Promise<InstantWithdrawQuote>;
92
+ /**
93
+ * Live quote for the ALV's own plain `instantWithdraw` (atomic-share holders): burn
94
+ * `shareAmount` ALV shares for `gross - fee`, no holdback, capped by
95
+ * `maxInstantWithdrawShares`. All inputs read live via RPC.
96
+ */
97
+ previewPlainInstantWithdraw(vaultAddress: string, shareAmount: bigint, owner: string): Promise<InstantWithdrawQuote>;
98
+ }