@zircuit/ovault-evm 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +141 -0
  2. package/dist/addresses.d.ts +41 -0
  3. package/dist/addresses.d.ts.map +1 -0
  4. package/dist/addresses.js +48 -0
  5. package/dist/contracts/EIP2612.d.ts +14 -0
  6. package/dist/contracts/EIP2612.d.ts.map +1 -0
  7. package/dist/contracts/EIP2612.js +38 -0
  8. package/dist/contracts/ERC20.d.ts +169 -0
  9. package/dist/contracts/ERC20.d.ts.map +1 -0
  10. package/dist/contracts/ERC20.js +222 -0
  11. package/dist/contracts/ERC4626.d.ts +2020 -0
  12. package/dist/contracts/ERC4626.d.ts.map +1 -0
  13. package/dist/contracts/ERC4626.js +2638 -0
  14. package/dist/contracts/OFT.d.ts +1736 -0
  15. package/dist/contracts/OFT.d.ts.map +1 -0
  16. package/dist/contracts/OFT.js +2251 -0
  17. package/dist/contracts/OVaultComposer.d.ts +94 -0
  18. package/dist/contracts/OVaultComposer.d.ts.map +1 -0
  19. package/dist/contracts/OVaultComposer.js +1629 -0
  20. package/dist/contracts/OVaultComposerSync.d.ts +528 -0
  21. package/dist/contracts/OVaultComposerSync.d.ts.map +1 -0
  22. package/dist/contracts/OVaultComposerSync.js +682 -0
  23. package/dist/contracts/OVaultComposerSyncNative.d.ts +560 -0
  24. package/dist/contracts/OVaultComposerSyncNative.d.ts.map +1 -0
  25. package/dist/contracts/OVaultComposerSyncNative.js +723 -0
  26. package/dist/index.d.ts +4 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +3 -0
  29. package/dist/oVaultSync/index.d.ts +3 -0
  30. package/dist/oVaultSync/index.d.ts.map +1 -0
  31. package/dist/oVaultSync/index.js +2 -0
  32. package/dist/oVaultSync/tracking.d.ts +46 -0
  33. package/dist/oVaultSync/tracking.d.ts.map +1 -0
  34. package/dist/oVaultSync/tracking.js +458 -0
  35. package/dist/oVaultSync/transfer.d.ts +116 -0
  36. package/dist/oVaultSync/transfer.d.ts.map +1 -0
  37. package/dist/oVaultSync/transfer.js +515 -0
  38. package/dist/types.d.ts +202 -0
  39. package/dist/types.d.ts.map +1 -0
  40. package/dist/types.js +18 -0
  41. package/package.json +51 -0
  42. package/src/addresses.ts +100 -0
  43. package/src/contracts/EIP2612.ts +38 -0
  44. package/src/contracts/ERC20.ts +222 -0
  45. package/src/contracts/ERC4626.ts +2638 -0
  46. package/src/contracts/OFT.ts +2251 -0
  47. package/src/contracts/OVaultComposer.ts +1629 -0
  48. package/src/contracts/OVaultComposerSync.ts +682 -0
  49. package/src/index.ts +3 -0
  50. package/src/oVaultSync/index.ts +2 -0
  51. package/src/oVaultSync/tracking.ts +614 -0
  52. package/src/oVaultSync/transfer.ts +742 -0
  53. package/src/types.ts +260 -0
package/src/types.ts ADDED
@@ -0,0 +1,260 @@
1
+ import { Chain as ViemChain } from "viem";
2
+ import { OFTAbi } from "./contracts/OFT";
3
+ import { OVaultComposerSyncAbi } from "./contracts/OVaultComposerSync";
4
+ import { ERC4626_ABI } from "./contracts/ERC4626";
5
+ import type { SupportedChainName, SupportedToken } from "./addresses";
6
+
7
+ export enum OVaultSyncOperations {
8
+ DEPOSIT = "deposit",
9
+ REDEEM = "redeem",
10
+ }
11
+
12
+ // --- Tracking helpers ---
13
+ export type OVaultWithdrawalInfo = {
14
+ index: bigint | number | string;
15
+ initiator: `0x${string}`;
16
+ };
17
+
18
+ export type OVaultMessageWithTxHash = {
19
+ source?: { tx?: { txHash?: `0x${string}` } };
20
+ };
21
+
22
+ export interface SendParamsInput {
23
+ srcEid: number;
24
+ hubEid: number;
25
+ dstEid: number;
26
+ dstAddress: `0x${string}`;
27
+ walletAddress: `0x${string}`;
28
+ referralCode?: string;
29
+
30
+ vaultAddress: `0x${string}`;
31
+ oftHubAddress: `0x${string}`;
32
+ composerAddress: `0x${string}`;
33
+ vaultTokenAddress: `0x${string}`;
34
+
35
+ // The Viem chain object for the hub chain. Require user to pass in the hub chain object so that
36
+ // not every viem chain needs to be bundled with the SDK.
37
+ hubChain: ViemChain;
38
+
39
+ // The Viem chain object for the source chain
40
+ sourceChain: ViemChain;
41
+
42
+ // Deposit or redeem
43
+ operation: OVaultSyncOperations;
44
+
45
+ // This is the amount of tokens to send
46
+ amount: bigint;
47
+
48
+ tokenHubDecimals?: number;
49
+
50
+ dstAmount: bigint;
51
+ // This is the minimum amount of tokens to receive. If you are sending the OFT Asset,
52
+ // then this is the minimum amount of shares to receive.
53
+ minDstAmount: bigint;
54
+
55
+ slippage: number; // How much slippage to allow for the redemption. This is a percentage, so 0.01 = 1%
56
+
57
+ oftAddress: `0x${string}`;
58
+ tokenAddress: `0x${string}`; // If a hex code equal to 0x0, then the native token is being sent
59
+
60
+ // Optional capability/quirk flags for approvals
61
+ supportsEip2612?: boolean;
62
+ requiresZeroApprovalReset?: boolean;
63
+
64
+ // The gas limit for the hub chain. Only needed if the hub chain is not the same as the source chain.
65
+ // Defaults to 375_000 for cross chain operations and 175_000 for same chain operations.
66
+ hubLzComposeGasLimit?: bigint;
67
+
68
+ // Additional percentage to add to the message fee calculation, rounded to the nearest whole percentage.
69
+ // For example, `0.05` and `0.051` both yield an extra 5%, while `0.055` yields 6%.
70
+ buffer?: number;
71
+
72
+ // Optional custom RPC URLs. When provided, these are used instead of the
73
+ // chain's default public RPC to avoid rate limiting.
74
+ hubRpcUrl?: string;
75
+ sourceRpcUrl?: string;
76
+ }
77
+
78
+ export type GenerateOVaultSyncInputsProps = Omit<
79
+ SendParamsInput,
80
+ | "dstAmount"
81
+ | "minDstAmount"
82
+ | "dstAddress"
83
+ | "hubChainSourceAmount"
84
+ | "amount"
85
+ > & {
86
+ // Unscaled (human-readable) amount string (e.g. "1.23")
87
+ amount: string;
88
+ // Decimals for parsing the unscaled amount into local chain units
89
+ tokenLocalDecimals: number;
90
+ dstAddress?: `0x${string}`;
91
+ };
92
+
93
+ /**
94
+ * Simplified input for `generateOVaultInputs`. The SDK resolves all contract
95
+ * addresses, EIDs, chain objects, and decimals from the built-in registry.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * const result = await OVaultSyncMessageBuilder.generateOVaultInputs({
100
+ * sourceChain: "ethereum",
101
+ * destinationChain: "base",
102
+ * token: "USDC",
103
+ * operation: OVaultSyncOperations.DEPOSIT,
104
+ * amount: "100",
105
+ * walletAddress: "0x...",
106
+ * });
107
+ * ```
108
+ */
109
+ export interface OVaultCoreInputs {
110
+ /** Chain where the user submits the transaction */
111
+ sourceChain: SupportedChainName;
112
+ /** Chain where tokens/shares are delivered */
113
+ destinationChain: SupportedChainName;
114
+ /** Token to deposit or redeem */
115
+ token: SupportedToken;
116
+ /** Deposit or redeem */
117
+ operation: OVaultSyncOperations;
118
+ /** Human-readable amount (e.g. "100" or "1.5") */
119
+ amount: string;
120
+ /** User's wallet address */
121
+ walletAddress: `0x${string}`;
122
+
123
+ // --- Optional overrides ---
124
+ /** Destination address (defaults to walletAddress) */
125
+ dstAddress?: `0x${string}`;
126
+ /** Slippage tolerance as a decimal (0.01 = 1%). Defaults to 0.01. */
127
+ slippage?: number;
128
+ /** Extra percentage buffer on the message fee. Defaults to 0.3 (30%). */
129
+ buffer?: number;
130
+ /** Whether the token supports EIP-2612 permit. Defaults to false. */
131
+ supportsEip2612?: boolean;
132
+ /** Override the LZ compose gas limit for cross-chain operations. */
133
+ hubLzComposeGasLimit?: bigint;
134
+ /** Referral code */
135
+ referralCode?: string;
136
+ /** Custom RPC URLs keyed by chain name. Avoids public RPC rate limits. */
137
+ rpcUrls?: Partial<Record<SupportedChainName, string>>;
138
+ }
139
+
140
+ /**
141
+ * The send parameters for the OVault. Pass this to the OFT or OVaultComposer to send the tokens.
142
+ *
143
+ * @typedef {Object} SendParams
144
+ * @property {number} dstEid - The destination chain ID.
145
+ * @property {`0x${string}`} to - The address of the destination contract.
146
+ * @property {bigint} amountLD - The amount of tokens to send.
147
+ * @property {bigint} minAmountLD - The minimum amount of tokens to receive.
148
+ * @property {`0x${string}`} extraOptions - The extra options for the OVault.
149
+ * @property {`0x${string}`} composeMsg - The compose message for the OVault.
150
+ * @property {`0x${string}`} oftCmd - The OFT command for the OVault.
151
+ */
152
+ export interface SendParams {
153
+ dstEid: number;
154
+ to: `0x${string}`;
155
+ amountLD: bigint;
156
+ minAmountLD: bigint;
157
+ extraOptions: `0x${string}`;
158
+ composeMsg: `0x${string}`;
159
+ oftCmd: `0x${string}`;
160
+ }
161
+
162
+ /**
163
+ * The message fee for the OVault.
164
+ *
165
+ * @typedef {Object} MessageFee
166
+ * @property {bigint} nativeFee - The native fee for the OVault.
167
+ * @property {bigint} lzTokenFee - The LZ token fee for the OVault.
168
+ */
169
+ export interface MessageFee {
170
+ nativeFee: bigint;
171
+ lzTokenFee: bigint;
172
+ }
173
+
174
+ /**
175
+ * The inputs for the OVault.
176
+ *
177
+ * @typedef {Object} OVaultInputs
178
+ * @property {MessageFee} messageFee - The message fee for the OVault.
179
+ * @property {`0x${string}`} contractAddress - The address of the contract to call.
180
+ * @property {Object} dstAmount - The amount of tokens to send.
181
+ * @property {Object} approval - The approval parameters for the OVault. If undefined, then no approval is needed.
182
+ * @property {Object} txArgs - The transaction arguments for the OVault.
183
+ */
184
+ export type OVaultSyncInputs = {
185
+ messageFee: MessageFee;
186
+ contractAddress: `0x${string}`;
187
+ dstAmount: {
188
+ amount: bigint;
189
+ minAmount: bigint;
190
+ };
191
+ approval?: {
192
+ tokenAddress: `0x${string}`;
193
+ amount: bigint;
194
+ spender: `0x${string}`;
195
+ usePermit?: boolean;
196
+ nonce?: bigint;
197
+ tokenName?: string;
198
+ tokenVersion?: string;
199
+ needsResetApproval?: boolean;
200
+ };
201
+ } & (
202
+ | {
203
+ txArgs: {
204
+ base: [SendParams, MessageFee, `0x${string}`];
205
+ permitParams: ["deadline", "v", "r", "s"] | null;
206
+ };
207
+ contractFunctionName: "send" | "sendWithPermit";
208
+ abi: typeof OFTAbi;
209
+ }
210
+ | {
211
+ txArgs: {
212
+ base: [bigint, SendParams, `0x${string}`];
213
+ permitParams: ["deadline", "v", "r", "s"] | null;
214
+ };
215
+ contractFunctionName:
216
+ | "depositAndSendWithPermit"
217
+ | "depositAndSend"
218
+ | "redeemAndSend";
219
+ abi: typeof OVaultComposerSyncAbi;
220
+ }
221
+ | {
222
+ txArgs: {
223
+ base: [bigint, `0x${string}`];
224
+ permitParams: null;
225
+ };
226
+ contractFunctionName: "deposit";
227
+ abi: typeof ERC4626_ABI;
228
+ }
229
+ | {
230
+ txArgs: {
231
+ base: [bigint, `0x${string}`, `0x${string}`];
232
+ permitParams: null;
233
+ };
234
+ contractFunctionName: "redeem";
235
+ abi: typeof ERC4626_ABI;
236
+ }
237
+ );
238
+
239
+ export enum OVaultTransactionStep {
240
+ SOURCE_CHAIN_TRANSACTION = "sourceChainTransaction",
241
+ SOURCE_TO_HUB_LZ_TRANSACTION = "sourceToHubLzTransaction",
242
+ HUB_CHAIN_TRANSACTION = "hubChainTransaction",
243
+ HUB_TO_DST_LZ_TRANSACTION = "hubToDstLzTransaction",
244
+ DST_CHAIN_TRANSACTION = "dstChainTransaction",
245
+ COMPLETED = "completed",
246
+ }
247
+
248
+ export enum OVaultFailureReason {
249
+ UNKNOWN = "unknown",
250
+ }
251
+
252
+ export interface OVaultTransactionStatus {
253
+ step: OVaultTransactionStep;
254
+
255
+ // If the transaction failed, this will be set
256
+ failureReason?: OVaultFailureReason;
257
+
258
+ // If the transaction was refunded, this will be set
259
+ refunded?: boolean;
260
+ }