@ember-finance/sdk 2.5.0 → 2.6.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.
- package/dist/src/abis/AtomicLiquidity.json +4050 -0
- package/dist/src/abis/ERC20Token.json +2 -2
- package/dist/src/abis/EmberETHVault.json +279 -5
- package/dist/src/abis/EmberProtocolConfig.json +170 -2
- package/dist/src/abis/EmberVault.json +2 -2
- package/dist/src/abis/EmberVaultMintBurnOFTAdapter.json +43 -2
- package/dist/src/api/v2/apis/accounts-api.d.ts +5 -0
- package/dist/src/api/v2/apis/accounts-api.js +6 -1
- package/dist/src/api/v2/apis/vaults-api.d.ts +16 -4
- package/dist/src/api/v2/apis/vaults-api.js +21 -7
- package/dist/src/api/v2/models/account-transaction-transaction-data.d.ts +5 -1
- package/dist/src/api/v2/models/account-transaction.d.ts +5 -0
- package/dist/src/api/v2/models/account-transaction.js +6 -1
- package/dist/src/api/v2/models/chain-vault-details.d.ts +14 -0
- package/dist/src/api/v2/models/escrow-claim-transaction.d.ts +56 -0
- package/dist/src/api/v2/models/escrow-claim-transaction.js +14 -0
- package/dist/src/api/v2/models/evm-atomic-liquidity-lib.d.ts +48 -0
- package/dist/src/api/v2/models/evm-atomic-liquidity-lib.js +14 -0
- package/dist/src/api/v2/models/evm-atomic-vault.d.ts +102 -0
- package/dist/src/api/v2/models/evm-atomic-vault.js +14 -0
- package/dist/src/api/v2/models/evm-contracts.d.ts +16 -0
- package/dist/src/api/v2/models/fee-multiplier-tier.d.ts +30 -0
- package/dist/src/api/v2/models/fee-multiplier-tier.js +14 -0
- package/dist/src/api/v2/models/holdback-release-transaction.d.ts +56 -0
- package/dist/src/api/v2/models/holdback-release-transaction.js +14 -0
- package/dist/src/api/v2/models/index.d.ts +9 -0
- package/dist/src/api/v2/models/index.js +9 -0
- package/dist/src/api/v2/models/instant-withdraw-config.d.ts +109 -0
- package/dist/src/api/v2/models/instant-withdraw-config.js +14 -0
- package/dist/src/api/v2/models/instant-withdraw-transaction.d.ts +74 -0
- package/dist/src/api/v2/models/instant-withdraw-transaction.js +14 -0
- package/dist/src/api/v2/models/instant-withdraw-via-swap-transaction.d.ts +74 -0
- package/dist/src/api/v2/models/instant-withdraw-via-swap-transaction.js +14 -0
- package/dist/src/api/v2/models/supported-ember-vault.d.ts +42 -0
- package/dist/src/api/v2/models/supported-ember-vault.js +14 -0
- package/dist/src/api/v2/models/vault-detail.d.ts +11 -0
- package/dist/src/api/v2/models/vault-detail.js +4 -0
- package/dist/src/atomic/instant-withdraw.d.ts +125 -0
- package/dist/src/atomic/instant-withdraw.js +122 -0
- package/dist/src/ember-vaults.d.ts +2 -1
- package/dist/src/evm-vaults/on-chain-calls/atomic-liquidity.d.ts +98 -0
- package/dist/src/evm-vaults/on-chain-calls/atomic-liquidity.js +212 -0
- package/dist/src/evm-vaults/on-chain-calls/index.d.ts +1 -0
- package/dist/src/evm-vaults/on-chain-calls/index.js +1 -0
- package/dist/src/evm-vaults/on-chain-calls/operator.d.ts +10 -0
- package/dist/src/evm-vaults/on-chain-calls/operator.js +28 -0
- package/dist/src/evm-vaults/on-chain-calls/tx-builder.d.ts +109 -0
- package/dist/src/evm-vaults/on-chain-calls/tx-builder.js +281 -0
- package/dist/src/evm-vaults/on-chain-calls/user.d.ts +50 -0
- package/dist/src/evm-vaults/on-chain-calls/user.js +75 -0
- package/dist/src/evm-vaults/on-chain-calls/vault-admin.d.ts +55 -0
- package/dist/src/evm-vaults/on-chain-calls/vault-admin.js +122 -0
- package/dist/src/evm-vaults/on-chain-calls/vault-reader.d.ts +6 -0
- package/dist/src/evm-vaults/on-chain-calls/vault-reader.js +9 -0
- package/dist/src/evm-vaults/utils/deployment-parser.d.ts +8 -0
- package/dist/src/evm-vaults/utils/deployment-parser.js +11 -0
- package/dist/src/sui-vaults/interfaces/index.d.ts +15 -0
- package/dist/src/sui-vaults/on-chain-calls/admin.d.ts +37 -1
- package/dist/src/sui-vaults/on-chain-calls/admin.js +56 -0
- package/dist/src/sui-vaults/on-chain-calls/atomic-liquidity.d.ts +62 -0
- package/dist/src/sui-vaults/on-chain-calls/atomic-liquidity.js +174 -0
- package/dist/src/sui-vaults/on-chain-calls/index.d.ts +1 -0
- package/dist/src/sui-vaults/on-chain-calls/index.js +1 -0
- package/dist/src/sui-vaults/on-chain-calls/onchain-calls.d.ts +2 -1
- package/dist/src/sui-vaults/on-chain-calls/operator.d.ts +129 -1
- package/dist/src/sui-vaults/on-chain-calls/operator.js +210 -0
- package/dist/src/sui-vaults/on-chain-calls/tx-builder.d.ts +482 -0
- package/dist/src/sui-vaults/on-chain-calls/tx-builder.js +1430 -0
- package/dist/src/sui-vaults/on-chain-calls/user.d.ts +107 -1
- package/dist/src/sui-vaults/on-chain-calls/user.js +190 -0
- package/dist/src/sui-vaults/on-chain-calls/vault-admin.d.ts +229 -1
- package/dist/src/sui-vaults/on-chain-calls/vault-admin.js +391 -0
- package/dist/src/sui-vaults/on-chain-calls/vault.d.ts +2 -1
- package/dist/src/sui-vaults/utils/common.d.ts +2 -1
- package/dist/src/sui-vaults/utils/deployment-parser.d.ts +12 -0
- package/dist/src/sui-vaults/utils/deployment-parser.js +24 -0
- package/package.json +3 -2
|
@@ -162,4 +162,59 @@ export declare class EVMVaultAdminCalls extends EVMOnChainCalls {
|
|
|
162
162
|
* @returns EvmOnChainCallResponse
|
|
163
163
|
*/
|
|
164
164
|
updateVaultName(vaultAddress: string, newName: string, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
165
|
+
/** Atomic vault: set the external ERC-4626 strategy (address(0) to disable). Drain the old strategy first. */
|
|
166
|
+
setStrategy(vaultAddress: string, caller: string, newStrategy: string, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
167
|
+
/**
|
|
168
|
+
* Atomic vault: whitelist (or update) a source EmberShare with fee / capacity / holdback /
|
|
169
|
+
* utilization percentages, a per-swap minimum gross floor, and an absolute held-value cap.
|
|
170
|
+
*
|
|
171
|
+
* @param minSwapGross Minimum gross collateral value per swap (collateral units); 0 disables
|
|
172
|
+
* the dust floor that would otherwise allow holdback-queue bloat.
|
|
173
|
+
* @param maxHeldValueAbsolute TVL-independent ceiling on this source share's post-swap held
|
|
174
|
+
* value (collateral units); 0 disables it.
|
|
175
|
+
*/
|
|
176
|
+
setEmberShareWhitelist(vaultAddress: string, caller: string, share: string, whitelisted: boolean, feePercentage: NumStr, maxCapacityPercentage: NumStr, holdbackPercentage: NumStr, maxUtilizationPercentage: NumStr, minSwapGross: NumStr, maxHeldValueAbsolute: NumStr, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
177
|
+
/** Atomic vault: set per-account swap waivers (fee and/or holdback); (false,false) removes them. */
|
|
178
|
+
setSwapWaiver(vaultAddress: string, caller: string, account: string, feeWaived: boolean, holdbackWaived: boolean, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
179
|
+
/**
|
|
180
|
+
* Atomic vault: add/update (remove=false) or remove (remove=true) a
|
|
181
|
+
* fee-multiplier curve tier for an EmberShare. `threshold` is a utilization
|
|
182
|
+
* percentage (1e18 = 100%); `multiplier` is a fee multiplier (1e18 = 1x, must
|
|
183
|
+
* be >= 1e18 on upsert). Admin only; routed through the protocol config.
|
|
184
|
+
*/
|
|
185
|
+
updateEmberShareFeeMultiplierTier(vaultAddress: string, caller: string, share: string, threshold: NumStr, multiplier: NumStr, remove: boolean, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
186
|
+
/** Atomic vault: set the cumulative instant-withdraw cap (in shares). */
|
|
187
|
+
setMaxInstantWithdrawShares(vaultAddress: string, caller: string, newMax: NumStr, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
188
|
+
/** Atomic vault: set the instant-withdraw fee percentage. */
|
|
189
|
+
setInstantWithdrawFeePercentage(vaultAddress: string, caller: string, newFeePercentage: NumStr, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
190
|
+
/** Atomic vault: set the platform fee percentage. */
|
|
191
|
+
setFeePercentage(vaultAddress: string, caller: string, newFeePercentage: NumStr, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
192
|
+
/** Atomic vault: set the maximum TVL. */
|
|
193
|
+
setMaxTVL(vaultAddress: string, caller: string, newMaxTVL: NumStr, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
194
|
+
/** Atomic vault: set the minimum withdrawable shares. */
|
|
195
|
+
setMinWithdrawableShares(vaultAddress: string, caller: string, newMinWithdrawableShares: NumStr, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
196
|
+
/** Atomic vault: set the max rate change per update bound. */
|
|
197
|
+
setMaxRateChangePerUpdate(vaultAddress: string, caller: string, newMaxRateChangePerUpdate: NumStr, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
198
|
+
/** Atomic vault: set the minimum interval between rate updates (ms). */
|
|
199
|
+
setRateUpdateInterval(vaultAddress: string, caller: string, newInterval: NumStr, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
200
|
+
/** Atomic vault: rename the vault. */
|
|
201
|
+
setVaultName(vaultAddress: string, caller: string, newName: string, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
202
|
+
/** Atomic vault: set the vault validator contract. */
|
|
203
|
+
setVaultValidator(vaultAddress: string, caller: string, validator: string, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
204
|
+
/** Atomic vault: add/remove a sub-account. */
|
|
205
|
+
setSubAccountStatus(vaultAddress: string, caller: string, account: string, isSubAccount: boolean, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
206
|
+
/** Atomic vault: pause/unpause an operation ("deposits" | "withdrawals" | "privilegedOperations"). */
|
|
207
|
+
setPausedStatus(vaultAddress: string, caller: string, operation: string, paused: boolean, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
208
|
+
/** Atomic vault: rotate the admin role. */
|
|
209
|
+
setAdmin(vaultAddress: string, caller: string, newAdmin: string, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
210
|
+
/** Atomic vault: rotate the operator role. */
|
|
211
|
+
setOperator(vaultAddress: string, caller: string, newOperator: string, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
212
|
+
/** Atomic vault: rotate the rate-manager role. */
|
|
213
|
+
setRateManager(vaultAddress: string, caller: string, newRateManager: string, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
214
|
+
/** Atomic vault: transfer contract ownership (UUPS owner). */
|
|
215
|
+
transferOwnership(vaultAddress: string, newOwner: string, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
216
|
+
/** Atomic vault: renounce ownership (irreversible). */
|
|
217
|
+
renounceOwnership(vaultAddress: string, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
218
|
+
/** Atomic vault: upgrade the implementation and optionally call init data (UUPS). */
|
|
219
|
+
upgradeToAndCall(vaultAddress: string, newImplementation: string, data: string, options?: IEvmCallOptions): Promise<EvmOnChainCallResponse>;
|
|
165
220
|
}
|
|
@@ -220,4 +220,126 @@ export class EVMVaultAdminCalls extends EVMOnChainCalls {
|
|
|
220
220
|
const txCall = this.txBuilder.updateVaultName(vaultAddress, newName);
|
|
221
221
|
return this.execCall(txCall, options);
|
|
222
222
|
}
|
|
223
|
+
// ============================================
|
|
224
|
+
// Atomic Liquidity Vault — vault admin actions (BFE-817/818)
|
|
225
|
+
// Gated via protocol-config; pass the admin as `caller`.
|
|
226
|
+
// ============================================
|
|
227
|
+
/** Atomic vault: set the external ERC-4626 strategy (address(0) to disable). Drain the old strategy first. */
|
|
228
|
+
async setStrategy(vaultAddress, caller, newStrategy, options) {
|
|
229
|
+
const txCall = this.txBuilder.atomicSetStrategy(vaultAddress, caller, newStrategy);
|
|
230
|
+
return this.execCall(txCall, options);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Atomic vault: whitelist (or update) a source EmberShare with fee / capacity / holdback /
|
|
234
|
+
* utilization percentages, a per-swap minimum gross floor, and an absolute held-value cap.
|
|
235
|
+
*
|
|
236
|
+
* @param minSwapGross Minimum gross collateral value per swap (collateral units); 0 disables
|
|
237
|
+
* the dust floor that would otherwise allow holdback-queue bloat.
|
|
238
|
+
* @param maxHeldValueAbsolute TVL-independent ceiling on this source share's post-swap held
|
|
239
|
+
* value (collateral units); 0 disables it.
|
|
240
|
+
*/
|
|
241
|
+
async setEmberShareWhitelist(vaultAddress, caller, share, whitelisted, feePercentage, maxCapacityPercentage, holdbackPercentage, maxUtilizationPercentage, minSwapGross, maxHeldValueAbsolute, options) {
|
|
242
|
+
const txCall = this.txBuilder.atomicSetEmberShareWhitelist(vaultAddress, caller, share, whitelisted, feePercentage, maxCapacityPercentage, holdbackPercentage, maxUtilizationPercentage, minSwapGross, maxHeldValueAbsolute);
|
|
243
|
+
return this.execCall(txCall, options);
|
|
244
|
+
}
|
|
245
|
+
/** Atomic vault: set per-account swap waivers (fee and/or holdback); (false,false) removes them. */
|
|
246
|
+
async setSwapWaiver(vaultAddress, caller, account, feeWaived, holdbackWaived, options) {
|
|
247
|
+
const txCall = this.txBuilder.atomicSetSwapWaiver(vaultAddress, caller, account, feeWaived, holdbackWaived);
|
|
248
|
+
return this.execCall(txCall, options);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Atomic vault: add/update (remove=false) or remove (remove=true) a
|
|
252
|
+
* fee-multiplier curve tier for an EmberShare. `threshold` is a utilization
|
|
253
|
+
* percentage (1e18 = 100%); `multiplier` is a fee multiplier (1e18 = 1x, must
|
|
254
|
+
* be >= 1e18 on upsert). Admin only; routed through the protocol config.
|
|
255
|
+
*/
|
|
256
|
+
async updateEmberShareFeeMultiplierTier(vaultAddress, caller, share, threshold, multiplier, remove, options) {
|
|
257
|
+
const txCall = this.txBuilder.atomicUpdateEmberShareFeeMultiplierTier(vaultAddress, caller, share, threshold, multiplier, remove);
|
|
258
|
+
return this.execCall(txCall, options);
|
|
259
|
+
}
|
|
260
|
+
/** Atomic vault: set the cumulative instant-withdraw cap (in shares). */
|
|
261
|
+
async setMaxInstantWithdrawShares(vaultAddress, caller, newMax, options) {
|
|
262
|
+
const txCall = this.txBuilder.atomicSetMaxInstantWithdrawShares(vaultAddress, caller, newMax);
|
|
263
|
+
return this.execCall(txCall, options);
|
|
264
|
+
}
|
|
265
|
+
/** Atomic vault: set the instant-withdraw fee percentage. */
|
|
266
|
+
async setInstantWithdrawFeePercentage(vaultAddress, caller, newFeePercentage, options) {
|
|
267
|
+
const txCall = this.txBuilder.atomicSetInstantWithdrawFeePercentage(vaultAddress, caller, newFeePercentage);
|
|
268
|
+
return this.execCall(txCall, options);
|
|
269
|
+
}
|
|
270
|
+
/** Atomic vault: set the platform fee percentage. */
|
|
271
|
+
async setFeePercentage(vaultAddress, caller, newFeePercentage, options) {
|
|
272
|
+
const txCall = this.txBuilder.atomicSetFeePercentage(vaultAddress, caller, newFeePercentage);
|
|
273
|
+
return this.execCall(txCall, options);
|
|
274
|
+
}
|
|
275
|
+
/** Atomic vault: set the maximum TVL. */
|
|
276
|
+
async setMaxTVL(vaultAddress, caller, newMaxTVL, options) {
|
|
277
|
+
const txCall = this.txBuilder.atomicSetMaxTVL(vaultAddress, caller, newMaxTVL);
|
|
278
|
+
return this.execCall(txCall, options);
|
|
279
|
+
}
|
|
280
|
+
/** Atomic vault: set the minimum withdrawable shares. */
|
|
281
|
+
async setMinWithdrawableShares(vaultAddress, caller, newMinWithdrawableShares, options) {
|
|
282
|
+
const txCall = this.txBuilder.atomicSetMinWithdrawableShares(vaultAddress, caller, newMinWithdrawableShares);
|
|
283
|
+
return this.execCall(txCall, options);
|
|
284
|
+
}
|
|
285
|
+
/** Atomic vault: set the max rate change per update bound. */
|
|
286
|
+
async setMaxRateChangePerUpdate(vaultAddress, caller, newMaxRateChangePerUpdate, options) {
|
|
287
|
+
const txCall = this.txBuilder.atomicSetMaxRateChangePerUpdate(vaultAddress, caller, newMaxRateChangePerUpdate);
|
|
288
|
+
return this.execCall(txCall, options);
|
|
289
|
+
}
|
|
290
|
+
/** Atomic vault: set the minimum interval between rate updates (ms). */
|
|
291
|
+
async setRateUpdateInterval(vaultAddress, caller, newInterval, options) {
|
|
292
|
+
const txCall = this.txBuilder.atomicSetRateUpdateInterval(vaultAddress, caller, newInterval);
|
|
293
|
+
return this.execCall(txCall, options);
|
|
294
|
+
}
|
|
295
|
+
/** Atomic vault: rename the vault. */
|
|
296
|
+
async setVaultName(vaultAddress, caller, newName, options) {
|
|
297
|
+
const txCall = this.txBuilder.atomicSetVaultName(vaultAddress, caller, newName);
|
|
298
|
+
return this.execCall(txCall, options);
|
|
299
|
+
}
|
|
300
|
+
/** Atomic vault: set the vault validator contract. */
|
|
301
|
+
async setVaultValidator(vaultAddress, caller, validator, options) {
|
|
302
|
+
const txCall = this.txBuilder.atomicSetVaultValidator(vaultAddress, caller, validator);
|
|
303
|
+
return this.execCall(txCall, options);
|
|
304
|
+
}
|
|
305
|
+
/** Atomic vault: add/remove a sub-account. */
|
|
306
|
+
async setSubAccountStatus(vaultAddress, caller, account, isSubAccount, options) {
|
|
307
|
+
const txCall = this.txBuilder.atomicSetSubAccountStatus(vaultAddress, caller, account, isSubAccount);
|
|
308
|
+
return this.execCall(txCall, options);
|
|
309
|
+
}
|
|
310
|
+
/** Atomic vault: pause/unpause an operation ("deposits" | "withdrawals" | "privilegedOperations"). */
|
|
311
|
+
async setPausedStatus(vaultAddress, caller, operation, paused, options) {
|
|
312
|
+
const txCall = this.txBuilder.atomicSetPausedStatus(vaultAddress, caller, operation, paused);
|
|
313
|
+
return this.execCall(txCall, options);
|
|
314
|
+
}
|
|
315
|
+
/** Atomic vault: rotate the admin role. */
|
|
316
|
+
async setAdmin(vaultAddress, caller, newAdmin, options) {
|
|
317
|
+
const txCall = this.txBuilder.atomicSetAdmin(vaultAddress, caller, newAdmin);
|
|
318
|
+
return this.execCall(txCall, options);
|
|
319
|
+
}
|
|
320
|
+
/** Atomic vault: rotate the operator role. */
|
|
321
|
+
async setOperator(vaultAddress, caller, newOperator, options) {
|
|
322
|
+
const txCall = this.txBuilder.atomicSetOperator(vaultAddress, caller, newOperator);
|
|
323
|
+
return this.execCall(txCall, options);
|
|
324
|
+
}
|
|
325
|
+
/** Atomic vault: rotate the rate-manager role. */
|
|
326
|
+
async setRateManager(vaultAddress, caller, newRateManager, options) {
|
|
327
|
+
const txCall = this.txBuilder.atomicSetRateManager(vaultAddress, caller, newRateManager);
|
|
328
|
+
return this.execCall(txCall, options);
|
|
329
|
+
}
|
|
330
|
+
/** Atomic vault: transfer contract ownership (UUPS owner). */
|
|
331
|
+
async transferOwnership(vaultAddress, newOwner, options) {
|
|
332
|
+
const txCall = this.txBuilder.atomicTransferOwnership(vaultAddress, newOwner);
|
|
333
|
+
return this.execCall(txCall, options);
|
|
334
|
+
}
|
|
335
|
+
/** Atomic vault: renounce ownership (irreversible). */
|
|
336
|
+
async renounceOwnership(vaultAddress, options) {
|
|
337
|
+
const txCall = this.txBuilder.atomicRenounceOwnership(vaultAddress);
|
|
338
|
+
return this.execCall(txCall, options);
|
|
339
|
+
}
|
|
340
|
+
/** Atomic vault: upgrade the implementation and optionally call init data (UUPS). */
|
|
341
|
+
async upgradeToAndCall(vaultAddress, newImplementation, data, options) {
|
|
342
|
+
const txCall = this.txBuilder.atomicUpgradeToAndCall(vaultAddress, newImplementation, data);
|
|
343
|
+
return this.execCall(txCall, options);
|
|
344
|
+
}
|
|
223
345
|
}
|
|
@@ -275,6 +275,12 @@ export declare class EVMVaultReader {
|
|
|
275
275
|
* @returns Total supply
|
|
276
276
|
*/
|
|
277
277
|
getTotalSupply(vaultAddress: string, isETHVault?: boolean): Promise<bigint>;
|
|
278
|
+
/**
|
|
279
|
+
* Escrowed (deferred) ETH withdrawal claimable by `account` on an EmberETHVault —
|
|
280
|
+
* accrued when a withdrawal couldn't be sent (the receiver rejected the ETH transfer).
|
|
281
|
+
* Claim via `claimWithdrawal` / `claimWithdrawalFor`. Returns 0 if none. EmberETHVault only.
|
|
282
|
+
*/
|
|
283
|
+
getUnclaimedWithdrawals(vaultAddress: string, account: string): Promise<bigint>;
|
|
278
284
|
/**
|
|
279
285
|
* Converts assets to shares
|
|
280
286
|
* @param vaultAddress The vault address
|
|
@@ -275,6 +275,15 @@ export class EVMVaultReader {
|
|
|
275
275
|
const vault = this.getVaultContract(vaultAddress, isETHVault);
|
|
276
276
|
return vault.totalSupply();
|
|
277
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* Escrowed (deferred) ETH withdrawal claimable by `account` on an EmberETHVault —
|
|
280
|
+
* accrued when a withdrawal couldn't be sent (the receiver rejected the ETH transfer).
|
|
281
|
+
* Claim via `claimWithdrawal` / `claimWithdrawalFor`. Returns 0 if none. EmberETHVault only.
|
|
282
|
+
*/
|
|
283
|
+
async getUnclaimedWithdrawals(vaultAddress, account) {
|
|
284
|
+
const vault = this.getVaultContract(vaultAddress, true);
|
|
285
|
+
return vault.unclaimedWithdrawals(account);
|
|
286
|
+
}
|
|
278
287
|
/**
|
|
279
288
|
* Converts assets to shares
|
|
280
289
|
* @param vaultAddress The vault address
|
|
@@ -20,6 +20,14 @@ export declare class EVMDeploymentParser {
|
|
|
20
20
|
* Gets the protocol config proxy address
|
|
21
21
|
*/
|
|
22
22
|
getProtocolConfigAddress(): string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Resolves the protocol config that governs a specific vault. Atomic Liquidity vaults can be
|
|
25
|
+
* deployed against their own protocol config (carried per-vault in the deployment), which may
|
|
26
|
+
* differ from the global one; admin ops for an atomic vault MUST route through that config.
|
|
27
|
+
* Falls back to the global protocol config for non-atomic vaults (and atomic vaults that don't
|
|
28
|
+
* specify one).
|
|
29
|
+
*/
|
|
30
|
+
getProtocolConfigAddressForVault(vaultAddress: string): string | undefined;
|
|
23
31
|
/**
|
|
24
32
|
* Gets the protocol config implementation address
|
|
25
33
|
*/
|
|
@@ -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 { BaseClient as SuiClient } from "@mysten/sui/client";
|
|
1
2
|
import { OnChainCalls } from "./onchain-calls.js";
|
|
2
3
|
import { ISuiDeployment, IVaultOptionalParams } from "../interfaces/index.js";
|
|
3
|
-
import { OnChainCallResponse, Signer, SuiAddress,
|
|
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 { BaseClient as SuiClient } from "@mysten/sui/client";
|
|
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
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseClient as SuiClient } from "@mysten/sui/client";
|
|
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";
|