@oydual31/more-vaults-sdk 0.1.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/README.md +283 -0
- package/dist/ethers/index.cjs +973 -0
- package/dist/ethers/index.cjs.map +1 -0
- package/dist/ethers/index.d.cts +671 -0
- package/dist/ethers/index.d.ts +671 -0
- package/dist/ethers/index.js +924 -0
- package/dist/ethers/index.js.map +1 -0
- package/dist/viem/index.cjs +1426 -0
- package/dist/viem/index.cjs.map +1 -0
- package/dist/viem/index.d.cts +1291 -0
- package/dist/viem/index.d.ts +1291 -0
- package/dist/viem/index.js +1377 -0
- package/dist/viem/index.js.map +1 -0
- package/package.json +46 -0
- package/src/ethers/abis.ts +82 -0
- package/src/ethers/crossChainFlows.ts +206 -0
- package/src/ethers/depositFlows.ts +347 -0
- package/src/ethers/errors.ts +81 -0
- package/src/ethers/index.ts +103 -0
- package/src/ethers/preflight.ts +156 -0
- package/src/ethers/redeemFlows.ts +286 -0
- package/src/ethers/types.ts +67 -0
- package/src/ethers/userHelpers.ts +480 -0
- package/src/ethers/utils.ts +377 -0
- package/src/viem/abis.ts +392 -0
- package/src/viem/crossChainFlows.ts +220 -0
- package/src/viem/depositFlows.ts +331 -0
- package/src/viem/errors.ts +81 -0
- package/src/viem/index.ts +100 -0
- package/src/viem/preflight.ts +204 -0
- package/src/viem/redeemFlows.ts +337 -0
- package/src/viem/types.ts +56 -0
- package/src/viem/userHelpers.ts +489 -0
- package/src/viem/utils.ts +421 -0
|
@@ -0,0 +1,671 @@
|
|
|
1
|
+
import { ContractTransactionReceipt, Signer, Provider } from 'ethers';
|
|
2
|
+
export { ContractTransactionReceipt, Provider, Signer } from 'ethers';
|
|
3
|
+
|
|
4
|
+
/** Addresses involved in vault operations. */
|
|
5
|
+
interface VaultAddresses {
|
|
6
|
+
/** Hub vault (diamond proxy) address. */
|
|
7
|
+
vault: string;
|
|
8
|
+
/** MoreVaultsEscrow address for cross-chain locking. */
|
|
9
|
+
escrow?: string;
|
|
10
|
+
/** OFTAdapter address for share token bridging (cross-chain only). */
|
|
11
|
+
shareOFT?: string;
|
|
12
|
+
/** OFT address for USDC bridging (cross-chain only). */
|
|
13
|
+
usdcOFT?: string;
|
|
14
|
+
}
|
|
15
|
+
/** Result of a synchronous deposit or mint. */
|
|
16
|
+
interface DepositResult {
|
|
17
|
+
receipt: ContractTransactionReceipt;
|
|
18
|
+
/** Number of vault shares minted. */
|
|
19
|
+
shares: bigint;
|
|
20
|
+
}
|
|
21
|
+
/** Result of a synchronous redeem or withdraw. */
|
|
22
|
+
interface RedeemResult {
|
|
23
|
+
receipt: ContractTransactionReceipt;
|
|
24
|
+
/** Number of underlying assets returned. */
|
|
25
|
+
assets: bigint;
|
|
26
|
+
}
|
|
27
|
+
/** Result of an asynchronous cross-chain request. */
|
|
28
|
+
interface AsyncRequestResult {
|
|
29
|
+
receipt: ContractTransactionReceipt;
|
|
30
|
+
/** bytes32 request GUID for tracking fulfillment. */
|
|
31
|
+
guid: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* ActionType enum matching MoreVaultsLib.ActionType on-chain values.
|
|
35
|
+
*
|
|
36
|
+
* DEPOSIT = 0, MINT = 1, WITHDRAW = 2, REDEEM = 3,
|
|
37
|
+
* MULTI_ASSETS_DEPOSIT = 4, ACCRUE_FEES = 5
|
|
38
|
+
*/
|
|
39
|
+
declare const ActionType: {
|
|
40
|
+
readonly DEPOSIT: 0;
|
|
41
|
+
readonly MINT: 1;
|
|
42
|
+
readonly WITHDRAW: 2;
|
|
43
|
+
readonly REDEEM: 3;
|
|
44
|
+
readonly MULTI_ASSETS_DEPOSIT: 4;
|
|
45
|
+
readonly ACCRUE_FEES: 5;
|
|
46
|
+
};
|
|
47
|
+
type ActionTypeValue = (typeof ActionType)[keyof typeof ActionType];
|
|
48
|
+
/** Cross-chain request info returned by getRequestInfo. */
|
|
49
|
+
interface CrossChainRequestInfo {
|
|
50
|
+
initiator: string;
|
|
51
|
+
timestamp: bigint;
|
|
52
|
+
actionType: number;
|
|
53
|
+
actionCallData: string;
|
|
54
|
+
fulfilled: boolean;
|
|
55
|
+
finalized: boolean;
|
|
56
|
+
refunded: boolean;
|
|
57
|
+
totalAssets: bigint;
|
|
58
|
+
finalizationResult: bigint;
|
|
59
|
+
amountLimit: bigint;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Human-readable ABI fragments for MoreVaults diamond facets.
|
|
64
|
+
* Extracted from compiled artifacts in out/.
|
|
65
|
+
*/
|
|
66
|
+
declare const VAULT_ABI: readonly ["function deposit(uint256 assets, address receiver) returns (uint256 shares)", "function mint(uint256 shares, address receiver) returns (uint256 assets)", "function withdraw(uint256 assets, address receiver, address owner) returns (uint256 shares)", "function redeem(uint256 shares, address receiver, address owner) returns (uint256 assets)", "function deposit(address[] tokens, uint256[] assets, address receiver, uint256 minAmountOut) payable returns (uint256 shares)", "function requestRedeem(uint256 shares, address onBehalfOf)", "function requestWithdraw(uint256 assets, address onBehalfOf)", "function clearRequest()", "function getWithdrawalRequest(address _owner) view returns (uint256 shares, uint256 timelockEndsAt)", "function totalAssets() view returns (uint256)", "function totalSupply() view returns (uint256)", "function balanceOf(address account) view returns (uint256)", "function asset() view returns (address)", "function convertToShares(uint256 assets) view returns (uint256)", "function convertToAssets(uint256 shares) view returns (uint256)", "function previewDeposit(uint256 assets) view returns (uint256)", "function previewRedeem(uint256 shares) view returns (uint256)", "function paused() view returns (bool)", "event Deposit(address indexed sender, address indexed owner, address[] tokens, uint256[] assets, uint256 shares)", "event Transfer(address indexed from, address indexed to, uint256 value)", "event WithdrawRequestCreated(address requester, uint256 sharesAmount, uint256 endsAt)", "event WithdrawRequestFulfilled(address requester, address receiver, uint256 sharesAmount, uint256 assetAmount)"];
|
|
67
|
+
declare const BRIDGE_ABI: readonly ["function initVaultActionRequest(uint8 actionType, bytes actionCallData, uint256 amountLimit, bytes extraOptions) payable returns (bytes32 guid)", "function getRequestInfo(bytes32 guid) view returns (tuple(address initiator, uint64 timestamp, uint8 actionType, bytes actionCallData, bool fulfilled, bool finalized, bool refunded, uint256 totalAssets, uint256 finalizationResult, uint256 amountLimit))", "function getFinalizationResult(bytes32 guid) view returns (uint256 result)", "function oraclesCrossChainAccounting() view returns (bool)", "function quoteAccountingFee(bytes extraOptions) view returns (uint256 nativeFee)", "function accountingBridgeFacet() view returns (uint256 sum, bool isPositive)"];
|
|
68
|
+
declare const CONFIG_ABI: readonly ["function getEscrow() view returns (address escrow)", "function getCrossChainAccountingManager() view returns (address)", "function isHub() view returns (bool)", "function getWithdrawalQueueStatus() view returns (bool)", "function getWithdrawalTimelock() view returns (uint64)", "function getWithdrawalFee() view returns (uint96)", "function getMaxWithdrawalDelay() view returns (uint32)", "function getAvailableAssets() view returns (address[])", "function getDepositableAssets() view returns (address[])", "function depositCapacity() view returns (uint256)", "function fee() view returns (uint96)", "function feeRecipient() view returns (address)", "function paused() view returns (bool)", "function maxDeposit(address receiver) view returns (uint256)"];
|
|
69
|
+
declare const METADATA_ABI: readonly ["function name() view returns (string)", "function symbol() view returns (string)", "function decimals() view returns (uint8)"];
|
|
70
|
+
declare const ERC20_ABI: readonly ["function approve(address spender, uint256 amount) returns (bool)", "function allowance(address owner, address spender) view returns (uint256)", "function balanceOf(address account) view returns (uint256)", "function transfer(address to, uint256 amount) returns (bool)"];
|
|
71
|
+
declare const OFT_ABI: readonly ["function send(tuple(uint32 dstEid, bytes32 to, uint256 amountLD, uint256 minAmountLD, bytes extraOptions, bytes composeMsg, bytes oftCmd) sendParam, tuple(uint256 nativeFee, uint256 lzTokenFee) fee, address refundAddress) payable returns (tuple(bytes32 guid, uint64 nonce, uint256 amountSentLD, uint256 amountReceivedLD) receipt, tuple(uint256 nativeFee, uint256 lzTokenFee) fee)", "function quoteSend(tuple(uint32 dstEid, bytes32 to, uint256 amountLD, uint256 minAmountLD, bytes extraOptions, bytes composeMsg, bytes oftCmd) sendParam, bool payInLzToken) view returns (tuple(uint256 nativeFee, uint256 lzTokenFee))"];
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Typed error classes for the MoreVaults SDK.
|
|
75
|
+
*
|
|
76
|
+
* Frontend code can use instanceof checks to handle errors programmatically:
|
|
77
|
+
* catch (e) {
|
|
78
|
+
* if (e instanceof InsufficientLiquidityError) { ... }
|
|
79
|
+
* }
|
|
80
|
+
*/
|
|
81
|
+
declare class MoreVaultsError extends Error {
|
|
82
|
+
constructor(message: string);
|
|
83
|
+
}
|
|
84
|
+
declare class VaultPausedError extends MoreVaultsError {
|
|
85
|
+
constructor(vault: string);
|
|
86
|
+
}
|
|
87
|
+
declare class CapacityFullError extends MoreVaultsError {
|
|
88
|
+
constructor(vault: string);
|
|
89
|
+
}
|
|
90
|
+
declare class NotWhitelistedError extends MoreVaultsError {
|
|
91
|
+
constructor(vault: string, user: string);
|
|
92
|
+
}
|
|
93
|
+
declare class InsufficientLiquidityError extends MoreVaultsError {
|
|
94
|
+
hubLiquid: bigint;
|
|
95
|
+
required: bigint;
|
|
96
|
+
constructor(vault: string, hubLiquid: bigint, required: bigint);
|
|
97
|
+
}
|
|
98
|
+
declare class CCManagerNotConfiguredError extends MoreVaultsError {
|
|
99
|
+
constructor(vault: string);
|
|
100
|
+
}
|
|
101
|
+
declare class EscrowNotConfiguredError extends MoreVaultsError {
|
|
102
|
+
constructor(vault: string);
|
|
103
|
+
}
|
|
104
|
+
declare class NotHubVaultError extends MoreVaultsError {
|
|
105
|
+
constructor(vault: string);
|
|
106
|
+
}
|
|
107
|
+
declare class MissingEscrowAddressError extends MoreVaultsError {
|
|
108
|
+
constructor();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Deposit `assets` of the vault's underlying token and receive shares.
|
|
113
|
+
*
|
|
114
|
+
* TXs: 1 approve (if needed) + 1 deposit.
|
|
115
|
+
*
|
|
116
|
+
* @param signer - Wallet that holds the underlying tokens.
|
|
117
|
+
* @param addresses - Vault addresses. Only `vault` is used.
|
|
118
|
+
* @param assets - Amount of underlying tokens to deposit.
|
|
119
|
+
* @param receiver - Address that will receive the minted shares.
|
|
120
|
+
* @returns Shares minted and the transaction receipt.
|
|
121
|
+
*/
|
|
122
|
+
declare function depositSimple(signer: Signer, addresses: VaultAddresses, assets: bigint, receiver: string): Promise<DepositResult>;
|
|
123
|
+
/**
|
|
124
|
+
* Deposit multiple tokens in a single transaction.
|
|
125
|
+
*
|
|
126
|
+
* TXs: N approves (if needed) + 1 deposit.
|
|
127
|
+
*
|
|
128
|
+
* @param signer - Wallet holding the tokens.
|
|
129
|
+
* @param addresses - Vault addresses. Only `vault` is used.
|
|
130
|
+
* @param tokens - Array of token addresses to deposit.
|
|
131
|
+
* @param amounts - Corresponding amounts for each token.
|
|
132
|
+
* @param receiver - Address that will receive the minted shares.
|
|
133
|
+
* @param minShares - Minimum acceptable shares (slippage protection).
|
|
134
|
+
* @returns Shares minted and the transaction receipt.
|
|
135
|
+
*/
|
|
136
|
+
declare function depositMultiAsset(signer: Signer, addresses: VaultAddresses, tokens: string[], amounts: bigint[], receiver: string, minShares: bigint): Promise<DepositResult>;
|
|
137
|
+
/**
|
|
138
|
+
* Deposit when cross-chain oracle accounting is ON.
|
|
139
|
+
* Behaves identically to a simple deposit because oracle provides
|
|
140
|
+
* synchronous pricing.
|
|
141
|
+
*
|
|
142
|
+
* TXs: 1 approve (if needed) + 1 deposit.
|
|
143
|
+
*/
|
|
144
|
+
declare const depositCrossChainOracleOn: typeof depositSimple;
|
|
145
|
+
/**
|
|
146
|
+
* Initiate an asynchronous cross-chain deposit request.
|
|
147
|
+
*
|
|
148
|
+
* CRITICAL: tokens are approved to the **escrow** address, not the vault.
|
|
149
|
+
*
|
|
150
|
+
* TXs: 1 approve to escrow (if needed) + 1 initVaultActionRequest.
|
|
151
|
+
* After this call, a LayerZero message is sent; the caller must wait for
|
|
152
|
+
* cross-chain fulfillment before shares are minted.
|
|
153
|
+
*
|
|
154
|
+
* @param signer - Wallet holding the underlying tokens.
|
|
155
|
+
* @param addresses - Must include `vault` and `escrow`.
|
|
156
|
+
* @param assets - Amount of underlying tokens to deposit.
|
|
157
|
+
* @param receiver - Address that will receive shares on fulfillment.
|
|
158
|
+
* @param lzFee - Native fee for LayerZero message (use `quoteLzFee`).
|
|
159
|
+
* @param extraOptions - Optional LZ adapter parameters (bytes).
|
|
160
|
+
* @returns The request GUID for tracking and the transaction receipt.
|
|
161
|
+
*/
|
|
162
|
+
declare function depositAsync(signer: Signer, addresses: VaultAddresses, assets: bigint, receiver: string, lzFee: bigint, extraOptions?: string): Promise<AsyncRequestResult>;
|
|
163
|
+
/**
|
|
164
|
+
* Initiate an asynchronous cross-chain mint request (exact shares).
|
|
165
|
+
*
|
|
166
|
+
* CRITICAL: tokens are approved to the **escrow** address, not the vault.
|
|
167
|
+
*
|
|
168
|
+
* TXs: 1 approve to escrow for maxAssets (if needed) + 1 initVaultActionRequest.
|
|
169
|
+
*
|
|
170
|
+
* @param signer - Wallet holding the underlying tokens.
|
|
171
|
+
* @param addresses - Must include `vault` and `escrow`.
|
|
172
|
+
* @param shares - Exact number of shares to mint.
|
|
173
|
+
* @param maxAssets - Maximum underlying tokens to spend (slippage cap).
|
|
174
|
+
* @param receiver - Address that will receive shares on fulfillment.
|
|
175
|
+
* @param lzFee - Native fee for LayerZero message.
|
|
176
|
+
* @param extraOptions - Optional LZ adapter parameters (bytes).
|
|
177
|
+
* @returns The request GUID for tracking and the transaction receipt.
|
|
178
|
+
*/
|
|
179
|
+
declare function mintAsync(signer: Signer, addresses: VaultAddresses, shares: bigint, maxAssets: bigint, receiver: string, lzFee: bigint, extraOptions?: string): Promise<AsyncRequestResult>;
|
|
180
|
+
/**
|
|
181
|
+
* Smart deposit — auto-selects the correct flow based on vault configuration.
|
|
182
|
+
*
|
|
183
|
+
* Calls getVaultStatus internally to determine the vault mode, then dispatches
|
|
184
|
+
* to the appropriate flow:
|
|
185
|
+
* - local / cross-chain-oracle → depositSimple
|
|
186
|
+
* - cross-chain-async → depositAsync (quotes LZ fee automatically)
|
|
187
|
+
*
|
|
188
|
+
* @param signer Wallet signer with account attached
|
|
189
|
+
* @param provider Read-only provider for on-chain reads
|
|
190
|
+
* @param addresses Vault address set (`escrow` required for async vaults)
|
|
191
|
+
* @param assets Amount of underlying to deposit
|
|
192
|
+
* @param receiver Address that will receive shares
|
|
193
|
+
* @param extraOptions Optional LZ extra options (only used for async vaults)
|
|
194
|
+
* @returns DepositResult or AsyncRequestResult depending on vault mode
|
|
195
|
+
* @throws VaultPausedError if vault is paused
|
|
196
|
+
* @throws CapacityFullError if vault is full
|
|
197
|
+
*/
|
|
198
|
+
declare function smartDeposit(signer: Signer, provider: Provider, addresses: VaultAddresses, assets: bigint, receiver: string, extraOptions?: string): Promise<DepositResult | AsyncRequestResult>;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* D6 / D7 — Deposit from a spoke chain to the hub vault via OFT Compose.
|
|
202
|
+
*
|
|
203
|
+
* Bridges tokens from the spoke chain to the hub via LayerZero OFT, attaching a
|
|
204
|
+
* composeMsg that instructs the hub-side MoreVaultsComposer to deposit into the vault
|
|
205
|
+
* and send the resulting shares back to the receiver on the spoke chain.
|
|
206
|
+
*
|
|
207
|
+
* - **D6 (oracle ON)**: composer calls `_depositAndSend` — shares arrive on spoke in ~1 LZ round-trip.
|
|
208
|
+
* - **D7 (oracle OFF)**: composer calls `_initDeposit` — requires an additional LZ Read round-trip.
|
|
209
|
+
*
|
|
210
|
+
* From the user's perspective, both D6 and D7 have the same interface.
|
|
211
|
+
*
|
|
212
|
+
* TXs: 1 approve (if needed) + 1 OFT.send().
|
|
213
|
+
* Wait: LayerZero cross-chain delivery (typically 1-5 minutes).
|
|
214
|
+
*
|
|
215
|
+
* @param signer - Wallet on the spoke chain.
|
|
216
|
+
* @param spokeOFT - OFT/OFTAdapter address on the spoke chain.
|
|
217
|
+
* @param hubEid - LayerZero EID for the hub chain (e.g. 30332 for Flow EVM).
|
|
218
|
+
* @param spokeEid - LayerZero EID for the spoke chain — where shares are sent back.
|
|
219
|
+
* @param amount - Amount of underlying tokens to bridge and deposit.
|
|
220
|
+
* @param receiver - Address that will receive shares on the spoke chain.
|
|
221
|
+
* @param lzFee - Native fee for the OFT.send() call. Must cover both hub-bound
|
|
222
|
+
* and return (shares back) messages. Quote via OFT.quoteSend().
|
|
223
|
+
* @param minMsgValue - Minimum msg.value the hub composer must receive to process
|
|
224
|
+
* the compose and send shares back. Defaults to 0.
|
|
225
|
+
* @param minSharesOut - Minimum shares to receive after deposit (slippage protection).
|
|
226
|
+
* Defaults to 0.
|
|
227
|
+
* @param minAmountLD - Minimum tokens received on hub after bridge. Defaults to `amount`.
|
|
228
|
+
* @param extraOptions - LZ extra options bytes for the hub-bound message.
|
|
229
|
+
* @returns Transaction receipt.
|
|
230
|
+
*/
|
|
231
|
+
declare function depositFromSpoke(signer: Signer, spokeOFT: string, hubEid: number, spokeEid: number, amount: bigint, receiver: string, lzFee: bigint, minMsgValue?: bigint, minSharesOut?: bigint, minAmountLD?: bigint, extraOptions?: string): Promise<{
|
|
232
|
+
receipt: ContractTransactionReceipt;
|
|
233
|
+
}>;
|
|
234
|
+
/**
|
|
235
|
+
* Alias: D7 — Spoke to hub deposit when oracle is OFF (async resolution).
|
|
236
|
+
* Same interface as D6; the difference is handled server-side by the composer contract.
|
|
237
|
+
* Shares may take longer to arrive due to the additional LZ Read round-trip.
|
|
238
|
+
*/
|
|
239
|
+
declare const depositFromSpokeAsync: typeof depositFromSpoke;
|
|
240
|
+
/**
|
|
241
|
+
* Quote the LayerZero fee required for depositFromSpoke / depositFromSpokeAsync.
|
|
242
|
+
*
|
|
243
|
+
* @param provider Read-only provider on the SPOKE chain
|
|
244
|
+
* @param spokeOFT OFT contract address on spoke chain
|
|
245
|
+
* @param hubEid LayerZero EID for the hub chain
|
|
246
|
+
* @param spokeEid LayerZero EID for the spoke chain
|
|
247
|
+
* @param amount Amount of tokens to bridge
|
|
248
|
+
* @param receiver Address that will receive vault shares on the spoke chain
|
|
249
|
+
* @param minMsgValue Same value you plan to pass to depositFromSpoke (default 0n)
|
|
250
|
+
* @param minSharesOut Same value you plan to pass to depositFromSpoke (default 0n)
|
|
251
|
+
* @param minAmountLD Minimum tokens on hub after bridge (default: amount)
|
|
252
|
+
* @param extraOptions LZ extra options (default 0x)
|
|
253
|
+
* @returns Native fee in wei to pass as lzFee to depositFromSpoke
|
|
254
|
+
*/
|
|
255
|
+
declare function quoteDepositFromSpokeFee(provider: Provider, spokeOFT: string, hubEid: number, spokeEid: number, amount: bigint, receiver: string, minMsgValue?: bigint, minSharesOut?: bigint, minAmountLD?: bigint, extraOptions?: string): Promise<bigint>;
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Redeem `shares` for underlying assets.
|
|
259
|
+
*
|
|
260
|
+
* TXs: 1 redeem.
|
|
261
|
+
* Pre-condition: if withdrawal queue is enabled, `requestRedeem` must have
|
|
262
|
+
* been called and the timelock must have elapsed.
|
|
263
|
+
*
|
|
264
|
+
* @param signer - Wallet holding the shares.
|
|
265
|
+
* @param addresses - Vault addresses. Only `vault` is used.
|
|
266
|
+
* @param shares - Number of shares to redeem.
|
|
267
|
+
* @param receiver - Address that will receive the underlying assets.
|
|
268
|
+
* @param owner - Address that owns the shares.
|
|
269
|
+
* @returns Assets received and the transaction receipt.
|
|
270
|
+
*/
|
|
271
|
+
declare function redeemShares(signer: Signer, addresses: VaultAddresses, shares: bigint, receiver: string, owner: string): Promise<RedeemResult>;
|
|
272
|
+
/**
|
|
273
|
+
* Withdraw exact `assets` amount of underlying tokens by burning shares.
|
|
274
|
+
*
|
|
275
|
+
* TXs: 1 withdraw.
|
|
276
|
+
*
|
|
277
|
+
* @param signer - Wallet holding the shares.
|
|
278
|
+
* @param addresses - Vault addresses. Only `vault` is used.
|
|
279
|
+
* @param assets - Exact amount of underlying tokens to withdraw.
|
|
280
|
+
* @param receiver - Address that will receive the tokens.
|
|
281
|
+
* @param owner - Address that owns the shares.
|
|
282
|
+
* @returns Assets received and the transaction receipt.
|
|
283
|
+
*/
|
|
284
|
+
declare function withdrawAssets(signer: Signer, addresses: VaultAddresses, assets: bigint, receiver: string, owner: string): Promise<RedeemResult>;
|
|
285
|
+
/**
|
|
286
|
+
* Submit a withdrawal queue request for `shares`.
|
|
287
|
+
*
|
|
288
|
+
* TXs: 1 requestRedeem.
|
|
289
|
+
* After this call and once any timelock elapses, call `redeemShares()` to
|
|
290
|
+
* complete the withdrawal.
|
|
291
|
+
*
|
|
292
|
+
* @param signer - Wallet holding the shares.
|
|
293
|
+
* @param addresses - Vault addresses. Only `vault` is used.
|
|
294
|
+
* @param shares - Number of shares to queue for redemption.
|
|
295
|
+
* @param owner - Address on whose behalf to request.
|
|
296
|
+
* @returns Transaction receipt.
|
|
297
|
+
*/
|
|
298
|
+
declare function requestRedeem(signer: Signer, addresses: VaultAddresses, shares: bigint, owner: string): Promise<{
|
|
299
|
+
receipt: ContractTransactionReceipt;
|
|
300
|
+
}>;
|
|
301
|
+
/**
|
|
302
|
+
* Get the current withdrawal request for an owner.
|
|
303
|
+
* Returns null if no pending request exists.
|
|
304
|
+
*
|
|
305
|
+
* @param provider - JSON-RPC provider.
|
|
306
|
+
* @param vault - Vault (diamond) address.
|
|
307
|
+
* @param owner - Address of the shares owner.
|
|
308
|
+
* @returns The request details or null.
|
|
309
|
+
*/
|
|
310
|
+
declare function getWithdrawalRequest(provider: Provider, vault: string, owner: string): Promise<{
|
|
311
|
+
shares: bigint;
|
|
312
|
+
timelockEndsAt: bigint;
|
|
313
|
+
} | null>;
|
|
314
|
+
/**
|
|
315
|
+
* Initiate an asynchronous cross-chain redeem request.
|
|
316
|
+
*
|
|
317
|
+
* CRITICAL: shares are approved to the **escrow** address (vault share token).
|
|
318
|
+
* amountLimit MUST be 0 for redeems.
|
|
319
|
+
*
|
|
320
|
+
* TXs: 1 approve to escrow for shares (if needed) + 1 initVaultActionRequest.
|
|
321
|
+
* Wait: LayerZero cross-chain fulfillment.
|
|
322
|
+
*
|
|
323
|
+
* @param signer - Wallet holding the shares.
|
|
324
|
+
* @param addresses - Must include `vault` and `escrow`.
|
|
325
|
+
* @param shares - Number of shares to redeem.
|
|
326
|
+
* @param receiver - Address that will receive the underlying assets.
|
|
327
|
+
* @param owner - Address that owns the shares.
|
|
328
|
+
* @param lzFee - Native fee for LayerZero message.
|
|
329
|
+
* @param extraOptions - Optional LZ adapter parameters (bytes).
|
|
330
|
+
* @returns The request GUID for tracking and the transaction receipt.
|
|
331
|
+
*/
|
|
332
|
+
declare function redeemAsync(signer: Signer, addresses: VaultAddresses, shares: bigint, receiver: string, owner: string, lzFee: bigint, extraOptions?: string): Promise<AsyncRequestResult>;
|
|
333
|
+
/**
|
|
334
|
+
* Bridge shares from a spoke chain to the hub chain (step 1 of 2).
|
|
335
|
+
*
|
|
336
|
+
* After the shares arrive on the hub chain, call `redeemShares()` on the
|
|
337
|
+
* hub to complete the redemption.
|
|
338
|
+
*
|
|
339
|
+
* TXs: 1 approve (if needed) + 1 OFT.send().
|
|
340
|
+
* Wait: LayerZero delivery (typically 1-5 minutes).
|
|
341
|
+
*
|
|
342
|
+
* @param signer - Wallet on the spoke chain holding shares.
|
|
343
|
+
* @param shareOFT - OFTAdapter address for the share token on spoke.
|
|
344
|
+
* @param hubChainEid - LayerZero endpoint ID for the hub chain (e.g. 30332 for Flow EVM).
|
|
345
|
+
* @param shares - Number of shares to bridge.
|
|
346
|
+
* @param receiver - Address on hub chain that will receive the shares.
|
|
347
|
+
* @param lzFee - Native fee for LayerZero message.
|
|
348
|
+
* @returns Transaction receipt.
|
|
349
|
+
*/
|
|
350
|
+
declare function bridgeSharesToHub(signer: Signer, shareOFT: string, hubChainEid: number, shares: bigint, receiver: string, lzFee: bigint): Promise<{
|
|
351
|
+
receipt: ContractTransactionReceipt;
|
|
352
|
+
}>;
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Utility helpers for the MoreVaults ethers.js v6 SDK.
|
|
356
|
+
*
|
|
357
|
+
* All reads use Provider (read-only). Writes use Signer.
|
|
358
|
+
*/
|
|
359
|
+
|
|
360
|
+
type VaultMode = "local" | "cross-chain-oracle" | "cross-chain-async" | "paused" | "full";
|
|
361
|
+
interface VaultStatus {
|
|
362
|
+
/** Vault operating mode — determines which SDK flow to use */
|
|
363
|
+
mode: VaultMode;
|
|
364
|
+
/** Which deposit function to call given the current configuration */
|
|
365
|
+
recommendedDepositFlow: "depositSimple" | "depositAsync" | "mintAsync" | "none";
|
|
366
|
+
/** Which redeem function to call given the current configuration */
|
|
367
|
+
recommendedRedeemFlow: "redeemShares" | "redeemAsync" | "none";
|
|
368
|
+
isHub: boolean;
|
|
369
|
+
isPaused: boolean;
|
|
370
|
+
oracleAccountingEnabled: boolean;
|
|
371
|
+
/** address(0) means CCManager is not set — async flows will fail */
|
|
372
|
+
ccManager: string;
|
|
373
|
+
/** address(0) means escrow is not configured in the registry */
|
|
374
|
+
escrow: string;
|
|
375
|
+
withdrawalQueueEnabled: boolean;
|
|
376
|
+
/** Timelock duration in seconds (0 = no timelock) */
|
|
377
|
+
withdrawalTimelockSeconds: bigint;
|
|
378
|
+
/**
|
|
379
|
+
* Remaining deposit capacity in underlying token decimals.
|
|
380
|
+
* `type(uint256).max` = no cap configured (unlimited).
|
|
381
|
+
* `0n` = vault is full — no more deposits accepted.
|
|
382
|
+
* If `depositAccessRestricted = true`, this value is `type(uint256).max` but
|
|
383
|
+
* deposits are still gated by whitelist or other access control.
|
|
384
|
+
*/
|
|
385
|
+
remainingDepositCapacity: bigint;
|
|
386
|
+
/**
|
|
387
|
+
* True when `maxDeposit(address(0))` reverted, indicating the vault uses
|
|
388
|
+
* whitelist or other access control to restrict who can deposit.
|
|
389
|
+
*/
|
|
390
|
+
depositAccessRestricted: boolean;
|
|
391
|
+
underlying: string;
|
|
392
|
+
totalAssets: bigint;
|
|
393
|
+
totalSupply: bigint;
|
|
394
|
+
/** Vault share token decimals. Use this for display — never hardcode 18. */
|
|
395
|
+
decimals: number;
|
|
396
|
+
/**
|
|
397
|
+
* Price of 1 full share expressed in underlying token units.
|
|
398
|
+
* = convertToAssets(10^decimals). Grows over time as the vault earns yield.
|
|
399
|
+
*/
|
|
400
|
+
sharePrice: bigint;
|
|
401
|
+
/**
|
|
402
|
+
* Underlying token balance held directly on the hub chain.
|
|
403
|
+
* This is the only portion that can be paid out to redeeming users immediately.
|
|
404
|
+
* (= ERC-20.balanceOf(vault) on the hub)
|
|
405
|
+
*/
|
|
406
|
+
hubLiquidBalance: bigint;
|
|
407
|
+
/**
|
|
408
|
+
* Approximate value deployed to spoke chains (totalAssets − hubLiquidBalance).
|
|
409
|
+
* These funds are NOT immediately redeemable — the vault curator must
|
|
410
|
+
* call executeBridging to repatriate them before large redeems can succeed.
|
|
411
|
+
*/
|
|
412
|
+
spokesDeployedBalance: bigint;
|
|
413
|
+
/**
|
|
414
|
+
* Maximum assets that can be redeemed right now without curator intervention.
|
|
415
|
+
* - For hub vaults: equals `hubLiquidBalance`.
|
|
416
|
+
* - For local/oracle vaults: equals `totalAssets`.
|
|
417
|
+
*/
|
|
418
|
+
maxImmediateRedeemAssets: bigint;
|
|
419
|
+
/**
|
|
420
|
+
* Human-readable list of configuration problems that would cause transactions
|
|
421
|
+
* to fail. Empty array = vault is ready to use.
|
|
422
|
+
*/
|
|
423
|
+
issues: string[];
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Ensure the spender has sufficient ERC-20 allowance; approve if not.
|
|
427
|
+
*
|
|
428
|
+
* @param signer Wallet signer with account attached
|
|
429
|
+
* @param provider Read-only provider for allowance checks
|
|
430
|
+
* @param token ERC-20 token address
|
|
431
|
+
* @param spender Address to approve
|
|
432
|
+
* @param amount Minimum required allowance
|
|
433
|
+
*/
|
|
434
|
+
declare function ensureAllowance(signer: Signer, provider: Provider, token: string, spender: string, amount: bigint): Promise<void>;
|
|
435
|
+
/**
|
|
436
|
+
* Quote the LayerZero native fee required for async vault actions.
|
|
437
|
+
*
|
|
438
|
+
* @param provider Read-only provider
|
|
439
|
+
* @param vault Vault address (diamond proxy)
|
|
440
|
+
* @param extraOptions Optional LZ extra options bytes (default 0x)
|
|
441
|
+
* @returns Required native fee in wei
|
|
442
|
+
*/
|
|
443
|
+
declare function quoteLzFee(provider: Provider, vault: string, extraOptions?: string): Promise<bigint>;
|
|
444
|
+
/**
|
|
445
|
+
* Check if a vault is operating in async mode (cross-chain hub with oracle OFF).
|
|
446
|
+
*
|
|
447
|
+
* @param provider Read-only provider
|
|
448
|
+
* @param vault Vault address
|
|
449
|
+
* @returns true if the vault requires async cross-chain flows
|
|
450
|
+
*/
|
|
451
|
+
declare function isAsyncMode(provider: Provider, vault: string): Promise<boolean>;
|
|
452
|
+
/**
|
|
453
|
+
* Poll for async request completion status.
|
|
454
|
+
*
|
|
455
|
+
* @param provider Read-only provider
|
|
456
|
+
* @param vault Vault address
|
|
457
|
+
* @param guid Request GUID returned by the async flow
|
|
458
|
+
* @returns Whether the request is fulfilled, finalized, and the result
|
|
459
|
+
*/
|
|
460
|
+
declare function getAsyncRequestStatus(provider: Provider, vault: string, guid: string): Promise<{
|
|
461
|
+
fulfilled: boolean;
|
|
462
|
+
finalized: boolean;
|
|
463
|
+
result: bigint;
|
|
464
|
+
}>;
|
|
465
|
+
/**
|
|
466
|
+
* Read the full configuration and operational status of a vault.
|
|
467
|
+
*
|
|
468
|
+
* All independent reads are fired in parallel.
|
|
469
|
+
*
|
|
470
|
+
* @param provider Read-only provider
|
|
471
|
+
* @param vault Vault address (diamond proxy)
|
|
472
|
+
* @returns Full vault status snapshot
|
|
473
|
+
*/
|
|
474
|
+
declare function getVaultStatus(provider: Provider, vault: string): Promise<VaultStatus>;
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Pre-flight validation helpers for MoreVaults ethers.js v6 SDK flows.
|
|
478
|
+
*
|
|
479
|
+
* Each function reads on-chain state and throws a descriptive error BEFORE
|
|
480
|
+
* the actual contract call, so developers see a clear, actionable message
|
|
481
|
+
* instead of a raw VM revert.
|
|
482
|
+
*/
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Pre-flight checks for async cross-chain flows (D4 / D5 / R5).
|
|
486
|
+
*
|
|
487
|
+
* Validates that:
|
|
488
|
+
* 1. The CCManager is configured on the vault.
|
|
489
|
+
* 2. An escrow is registered in the vault's registry.
|
|
490
|
+
* 3. The vault is a hub (required for async flows).
|
|
491
|
+
* 4. The vault does NOT have oracle-based cross-chain accounting enabled
|
|
492
|
+
* (oracle-on vaults should use depositSimple / depositCrossChainOracleOn).
|
|
493
|
+
* 5. The vault is not paused.
|
|
494
|
+
*
|
|
495
|
+
* All reads that are independent of each other are executed in parallel via
|
|
496
|
+
* Promise.all to minimise latency.
|
|
497
|
+
*
|
|
498
|
+
* @param provider Read-only provider for contract reads
|
|
499
|
+
* @param vault Vault address (diamond proxy)
|
|
500
|
+
* @param escrow Escrow address from VaultAddresses
|
|
501
|
+
*/
|
|
502
|
+
declare function preflightAsync(provider: Provider, vault: string, escrow: string): Promise<void>;
|
|
503
|
+
/**
|
|
504
|
+
* Pre-flight liquidity check for async redeem (R5).
|
|
505
|
+
*
|
|
506
|
+
* Reads the hub's liquid balance of the underlying token and compares it
|
|
507
|
+
* against the assets the user expects to receive. If the hub does not hold
|
|
508
|
+
* enough liquid assets the redeem will be auto-refunded after the LZ round-trip,
|
|
509
|
+
* wasting the LayerZero fee.
|
|
510
|
+
*
|
|
511
|
+
* @param provider Read-only provider for contract reads
|
|
512
|
+
* @param vault Vault address (diamond proxy)
|
|
513
|
+
* @param shares Shares the user intends to redeem
|
|
514
|
+
*/
|
|
515
|
+
declare function preflightRedeemLiquidity(provider: Provider, vault: string, shares: bigint): Promise<void>;
|
|
516
|
+
/**
|
|
517
|
+
* Pre-flight checks for synchronous deposit flows (D1 / D3).
|
|
518
|
+
*
|
|
519
|
+
* Validates that:
|
|
520
|
+
* 1. The vault is not paused.
|
|
521
|
+
* 2. The vault still has deposit capacity (maxDeposit > 0).
|
|
522
|
+
*
|
|
523
|
+
* Both reads are executed in parallel.
|
|
524
|
+
*
|
|
525
|
+
* @param provider Read-only provider for contract reads
|
|
526
|
+
* @param vault Vault address (diamond proxy)
|
|
527
|
+
*/
|
|
528
|
+
declare function preflightSync(provider: Provider, vault: string): Promise<void>;
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* User-facing helper functions for the MoreVaults ethers.js v6 SDK.
|
|
532
|
+
*
|
|
533
|
+
* All functions use Provider (read-only). None send transactions.
|
|
534
|
+
*/
|
|
535
|
+
|
|
536
|
+
interface UserPosition {
|
|
537
|
+
/** Vault share balance */
|
|
538
|
+
shares: bigint;
|
|
539
|
+
/** convertToAssets(shares) — what they'd get if they redeemed now */
|
|
540
|
+
estimatedAssets: bigint;
|
|
541
|
+
/** Price of 1 full share in underlying (convertToAssets(10n ** decimals)) */
|
|
542
|
+
sharePrice: bigint;
|
|
543
|
+
/** Vault decimals (for display) */
|
|
544
|
+
decimals: number;
|
|
545
|
+
pendingWithdrawal: {
|
|
546
|
+
shares: bigint;
|
|
547
|
+
timelockEndsAt: bigint;
|
|
548
|
+
/** block.timestamp >= timelockEndsAt (or timelockEndsAt === 0n) */
|
|
549
|
+
canRedeemNow: boolean;
|
|
550
|
+
} | null;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Read the user's current position in the vault.
|
|
554
|
+
*
|
|
555
|
+
* @param provider Read-only provider for reads
|
|
556
|
+
* @param vault Vault address (diamond proxy)
|
|
557
|
+
* @param user User wallet address
|
|
558
|
+
* @returns Full user position snapshot
|
|
559
|
+
*/
|
|
560
|
+
declare function getUserPosition(provider: Provider, vault: string, user: string): Promise<UserPosition>;
|
|
561
|
+
/**
|
|
562
|
+
* Preview how many shares a given asset amount would mint.
|
|
563
|
+
*
|
|
564
|
+
* @param provider Read-only provider
|
|
565
|
+
* @param vault Vault address
|
|
566
|
+
* @param assets Amount of underlying tokens to deposit
|
|
567
|
+
* @returns Estimated shares to be minted
|
|
568
|
+
*/
|
|
569
|
+
declare function previewDeposit(provider: Provider, vault: string, assets: bigint): Promise<bigint>;
|
|
570
|
+
/**
|
|
571
|
+
* Preview how many underlying assets a given share amount would redeem.
|
|
572
|
+
*
|
|
573
|
+
* @param provider Read-only provider
|
|
574
|
+
* @param vault Vault address
|
|
575
|
+
* @param shares Amount of vault shares to redeem
|
|
576
|
+
* @returns Estimated assets to be returned
|
|
577
|
+
*/
|
|
578
|
+
declare function previewRedeem(provider: Provider, vault: string, shares: bigint): Promise<bigint>;
|
|
579
|
+
type DepositBlockReason = "paused" | "capacity-full" | "not-whitelisted" | "ok";
|
|
580
|
+
interface DepositEligibility {
|
|
581
|
+
allowed: boolean;
|
|
582
|
+
reason: DepositBlockReason;
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Check whether a user is eligible to deposit into the vault right now.
|
|
586
|
+
*
|
|
587
|
+
* @param provider Read-only provider
|
|
588
|
+
* @param vault Vault address
|
|
589
|
+
* @param user User wallet address
|
|
590
|
+
* @returns Eligibility result with reason
|
|
591
|
+
*/
|
|
592
|
+
declare function canDeposit(provider: Provider, vault: string, user: string): Promise<DepositEligibility>;
|
|
593
|
+
interface VaultMetadata {
|
|
594
|
+
name: string;
|
|
595
|
+
symbol: string;
|
|
596
|
+
decimals: number;
|
|
597
|
+
underlying: string;
|
|
598
|
+
underlyingSymbol: string;
|
|
599
|
+
underlyingDecimals: number;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Read display metadata for a vault and its underlying token.
|
|
603
|
+
*
|
|
604
|
+
* @param provider Read-only provider
|
|
605
|
+
* @param vault Vault address
|
|
606
|
+
* @returns Vault and underlying token metadata
|
|
607
|
+
*/
|
|
608
|
+
declare function getVaultMetadata(provider: Provider, vault: string): Promise<VaultMetadata>;
|
|
609
|
+
type AsyncRequestStatus = "pending" | "ready-to-execute" | "completed" | "refunded";
|
|
610
|
+
interface AsyncRequestStatusInfo {
|
|
611
|
+
status: AsyncRequestStatus;
|
|
612
|
+
/** Human-readable description */
|
|
613
|
+
label: string;
|
|
614
|
+
/** Shares minted or assets returned (0 if still pending) */
|
|
615
|
+
result: bigint;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Get the human-readable status of an async cross-chain request.
|
|
619
|
+
*
|
|
620
|
+
* @param provider Read-only provider
|
|
621
|
+
* @param vault Vault address
|
|
622
|
+
* @param guid Request GUID returned by depositAsync / mintAsync / redeemAsync
|
|
623
|
+
* @returns Status info with label and result
|
|
624
|
+
*/
|
|
625
|
+
declare function getAsyncRequestStatusLabel(provider: Provider, vault: string, guid: string): Promise<AsyncRequestStatusInfo>;
|
|
626
|
+
interface UserBalances {
|
|
627
|
+
/** Vault shares the user holds */
|
|
628
|
+
shareBalance: bigint;
|
|
629
|
+
/** Underlying token balance in wallet (for deposit input) */
|
|
630
|
+
underlyingBalance: bigint;
|
|
631
|
+
/** convertToAssets(shareBalance) — vault position value */
|
|
632
|
+
estimatedAssets: bigint;
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Read the user's token balances relevant to a vault.
|
|
636
|
+
*
|
|
637
|
+
* @param provider Read-only provider
|
|
638
|
+
* @param vault Vault address
|
|
639
|
+
* @param user User wallet address
|
|
640
|
+
* @returns Share balance, underlying wallet balance, and estimated assets
|
|
641
|
+
*/
|
|
642
|
+
declare function getUserBalances(provider: Provider, vault: string, user: string): Promise<UserBalances>;
|
|
643
|
+
interface MaxWithdrawable {
|
|
644
|
+
/** How many shares can be redeemed right now */
|
|
645
|
+
shares: bigint;
|
|
646
|
+
/** How many underlying assets that corresponds to */
|
|
647
|
+
assets: bigint;
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Calculate the maximum amount a user can withdraw from a vault right now.
|
|
651
|
+
*
|
|
652
|
+
* For hub vaults without oracle accounting, this is limited by hub liquidity.
|
|
653
|
+
* For local and oracle vaults, all assets are immediately redeemable.
|
|
654
|
+
*
|
|
655
|
+
* @param provider Read-only provider
|
|
656
|
+
* @param vault Vault address
|
|
657
|
+
* @param user User wallet address
|
|
658
|
+
* @returns Maximum withdrawable shares and assets
|
|
659
|
+
*/
|
|
660
|
+
declare function getMaxWithdrawable(provider: Provider, vault: string, user: string): Promise<MaxWithdrawable>;
|
|
661
|
+
type VaultSummary = VaultStatus & VaultMetadata;
|
|
662
|
+
/**
|
|
663
|
+
* Get a combined snapshot of vault status and metadata in one call.
|
|
664
|
+
*
|
|
665
|
+
* @param provider Read-only provider
|
|
666
|
+
* @param vault Vault address
|
|
667
|
+
* @returns Merged VaultStatus and VaultMetadata
|
|
668
|
+
*/
|
|
669
|
+
declare function getVaultSummary(provider: Provider, vault: string): Promise<VaultSummary>;
|
|
670
|
+
|
|
671
|
+
export { ActionType, type ActionTypeValue, type AsyncRequestResult, type AsyncRequestStatus, type AsyncRequestStatusInfo, BRIDGE_ABI, CCManagerNotConfiguredError, CONFIG_ABI, CapacityFullError, type CrossChainRequestInfo, type DepositBlockReason, type DepositEligibility, type DepositResult, ERC20_ABI, EscrowNotConfiguredError, InsufficientLiquidityError, METADATA_ABI, type MaxWithdrawable, MissingEscrowAddressError, MoreVaultsError, NotHubVaultError, NotWhitelistedError, OFT_ABI, type RedeemResult, type UserBalances, type UserPosition, VAULT_ABI, type VaultAddresses, type VaultMetadata, type VaultMode, VaultPausedError, type VaultStatus, type VaultSummary, bridgeSharesToHub, canDeposit, depositAsync, depositCrossChainOracleOn, depositFromSpoke, depositFromSpokeAsync, depositMultiAsset, depositSimple, ensureAllowance, getAsyncRequestStatus, getAsyncRequestStatusLabel, getMaxWithdrawable, getUserBalances, getUserPosition, getVaultMetadata, getVaultStatus, getVaultSummary, getWithdrawalRequest, isAsyncMode, mintAsync, preflightAsync, preflightRedeemLiquidity, preflightSync, previewDeposit, previewRedeem, quoteDepositFromSpokeFee, quoteLzFee, redeemAsync, redeemShares, requestRedeem, smartDeposit, withdrawAssets };
|