@wayne-zhang/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 (55) hide show
  1. package/README.md +141 -0
  2. package/artifacts/IVaultComposerSync.sol/IVaultComposerSync.json +1126 -0
  3. package/artifacts/IVaultComposerSyncNative.sol/IVaultComposerSyncNative.json +323 -0
  4. package/artifacts/VaultComposerSync.sol/VaultComposerSync.json +1399 -0
  5. package/artifacts/VaultComposerSyncNative.sol/VaultComposerSyncNative.json +1540 -0
  6. package/dist/contracts/EIP2612.d.ts +14 -0
  7. package/dist/contracts/EIP2612.d.ts.map +1 -0
  8. package/dist/contracts/EIP2612.js +38 -0
  9. package/dist/contracts/ERC20.d.ts +169 -0
  10. package/dist/contracts/ERC20.d.ts.map +1 -0
  11. package/dist/contracts/ERC20.js +222 -0
  12. package/dist/contracts/ERC4626.d.ts +2020 -0
  13. package/dist/contracts/ERC4626.d.ts.map +1 -0
  14. package/dist/contracts/ERC4626.js +2638 -0
  15. package/dist/contracts/OFT.d.ts +1736 -0
  16. package/dist/contracts/OFT.d.ts.map +1 -0
  17. package/dist/contracts/OFT.js +2251 -0
  18. package/dist/contracts/OVaultComposer.d.ts +94 -0
  19. package/dist/contracts/OVaultComposer.d.ts.map +1 -0
  20. package/dist/contracts/OVaultComposer.js +1629 -0
  21. package/dist/contracts/OVaultComposerSync.d.ts +528 -0
  22. package/dist/contracts/OVaultComposerSync.d.ts.map +1 -0
  23. package/dist/contracts/OVaultComposerSync.js +682 -0
  24. package/dist/contracts/OVaultComposerSyncNative.d.ts +560 -0
  25. package/dist/contracts/OVaultComposerSyncNative.d.ts.map +1 -0
  26. package/dist/contracts/OVaultComposerSyncNative.js +723 -0
  27. package/dist/index.d.ts +3 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +2 -0
  30. package/dist/oVaultSync/index.d.ts +3 -0
  31. package/dist/oVaultSync/index.d.ts.map +1 -0
  32. package/dist/oVaultSync/index.js +2 -0
  33. package/dist/oVaultSync/tracking.d.ts +39 -0
  34. package/dist/oVaultSync/tracking.d.ts.map +1 -0
  35. package/dist/oVaultSync/tracking.js +458 -0
  36. package/dist/oVaultSync/transfer.d.ts +94 -0
  37. package/dist/oVaultSync/transfer.d.ts.map +1 -0
  38. package/dist/oVaultSync/transfer.js +431 -0
  39. package/dist/types.d.ts +149 -0
  40. package/dist/types.d.ts.map +1 -0
  41. package/dist/types.js +18 -0
  42. package/package.json +87 -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 +2 -0
  50. package/src/oVaultSync/index.ts +2 -0
  51. package/src/oVaultSync/tracking.ts +623 -0
  52. package/src/oVaultSync/transfer.ts +615 -0
  53. package/src/types.ts +201 -0
  54. package/test/sdk/tracker.test.ts +18 -0
  55. package/test/sdk/transfer.test.ts +330 -0
package/README.md ADDED
@@ -0,0 +1,141 @@
1
+ ## Installation
2
+
3
+ ```bash
4
+ pnpm add @wayne-zhang/ovault-evm
5
+ ```
6
+
7
+ ```bash
8
+ npm install @wayne-zhang/ovault-evm
9
+ ```
10
+
11
+ ## OVault SDK
12
+
13
+ This is an SDK to make depositing/redeeming on OVaults simple.
14
+
15
+ ### Usage
16
+
17
+ All information required can be retrieved by calling `OVaultSyncMessageBuilder.generateOVaultInputs`.
18
+
19
+ You pass a `GenerateOVaultSyncInputsProps` object (see `src/types.ts`). Key points:
20
+
21
+ - **`amount` is an unscaled string** (e.g. `"1.23"`)
22
+ - **`tokenLocalDecimals`** is required to parse the unscaled amount into local-chain units
23
+ - **`tokenHubDecimals`** should be the asset/share decimals on the **hub chain** (used for `previewDeposit` / `previewRedeem`)
24
+ - **`txArgs`** is now an object: `{ base: [...], permitParams: [...] | null }`
25
+ - Optional **EIP-2612** support via `supportsEip2612` + `sendWithPermit` / `depositAndSendWithPermit`
26
+
27
+ ```typescript
28
+ {
29
+ srcEid: number,
30
+ hubEid: number,
31
+ dstEid: number,
32
+ walletAddress: `0x${string}`,
33
+ dstAddress?: `0x${string}`, // If no dstAddress is supplied, it's assumed to be the same as the source wallet address
34
+ vaultAddress: `0x${string}`,
35
+ composerAddress: `0x${string}`,
36
+ oftHubAddress: `0x${string}`, // hub-chain underlying OFT (used for hub redeem quotes/fees)
37
+ vaultTokenAddress: `0x${string}`, // source-chain VaultToken (shares) OFT address (used for spoke redeem quotes/fees)
38
+ hubChain: Chain, // This is a Viem chain definition
39
+ sourceChain: Chain, // This is a Viem chain definition
40
+ operation: OVaultSyncOperations,
41
+ amount: string, // unscaled string (e.g. "1.23")
42
+ tokenLocalDecimals: number,
43
+ tokenHubDecimals?: number,
44
+ slippage: number, // such as 0.01 for 1% slippage
45
+ buffer?: number, // optional fee buffer (e.g. 0.3 => +30%)
46
+ referralCode?: string, // optional referral code forwarded via oftCmd
47
+ oftAddress: `0x${string}`, // source-chain OFT/OFTAdapter address
48
+ tokenAddress: `0x${string}`, // source-chain ERC20 address (or 0x0 for native)
49
+ supportsEip2612?: boolean,
50
+ requiresZeroApprovalReset?: boolean,
51
+ }
52
+ ```
53
+
54
+ For full information about the input object check `GenerateOVaultSyncInputsProps` in `src/types.ts`.
55
+
56
+ You will receive an `OVaultSyncInputs` object back containing all information you need to build the transaction.
57
+
58
+ ### Example
59
+
60
+ #### Base Functionality
61
+
62
+ Below is an example of how to deposit tokens using the Viem client on a server side environment.
63
+
64
+ ```typescript
65
+ const input = {
66
+ srcEid: 40245, // eid for base-sepolia
67
+ hubEid: 40231, // eid for arbitrum-sepolia
68
+ dstEid: 40245, // eid for base-sepolia
69
+
70
+ // Optional. If dstAddress is not specified it will default to the walletAddress on the dst chain
71
+ dstAddress: "0x0000000000000000000000000000000000000000",
72
+ walletAddress: "0x0000000000000000000000000000000000000000",
73
+ vaultAddress: "0x0000000000000000000000000000000000000000",
74
+
75
+ // Address of the OVault Composer on the Hub Chain. Should implement IVaultComposerSync
76
+ composerAddress: "0x0000000000000000000000000000000000000000",
77
+ oftHubAddress: "0x0000000000000000000000000000000000000000",
78
+ vaultTokenAddress: "0x0000000000000000000000000000000000000000",
79
+
80
+ // Supply the Viem Chain Definitions for the hub and source chain. This is so the sdk can
81
+ // quote fees and perform read operations
82
+ hubChain: arbitrumSepolia,
83
+ sourceChain: baseSepolia,
84
+ operation: OVaultSyncOperations.DEPOSIT,
85
+ amount: "1.0", // unscaled string
86
+ tokenLocalDecimals: 18,
87
+ tokenHubDecimals: 18,
88
+ slippage: 0.01, // 1% slippage
89
+
90
+ // Address of the token/oft. The token is an ERC20. They can be the same address.
91
+ tokenAddress: "0x0000000000000000000000000000000000000000",
92
+ oftAddress: "0x0000000000000000000000000000000000000000",
93
+ } as const;
94
+
95
+ const inputs = await OVaultSyncMessageBuilder.generateOVaultInputs(input);
96
+ const account = privateKeyToAccount("YOUR PRIVATE KEY HERE");
97
+
98
+ const walletClient = createWalletClient({
99
+ account,
100
+ chain: srcChain.chain,
101
+ transport: http(),
102
+ }).extend(publicActions);
103
+
104
+ if (inputs.approval) {
105
+ // Approve token if required
106
+ const approvalTx = await walletClient.writeContract({
107
+ address: inputs.approval.tokenAddress,
108
+ abi: ERC20Abi,
109
+ functionName: "approve",
110
+ args: [inputs.approval.spender, inputs.approval.amount],
111
+ });
112
+ await walletClient.waitForTransactionReceipt({ hash: approvalTx });
113
+ }
114
+
115
+ const tx = await walletClient.writeContract({
116
+ address: inputs.contractAddress,
117
+ abi: inputs.abi,
118
+ value: inputs.messageFee.nativeFee,
119
+ functionName: inputs.contractFunctionName,
120
+ args: inputs.txArgs.base as any,
121
+ });
122
+ ```
123
+
124
+ For more example usage see `test/sdk/transfer.test.ts`.
125
+
126
+ ## Tracking transactions
127
+
128
+ To track cross-chain progress, use:
129
+
130
+ ```ts
131
+ import { trackOVaultSyncTransaction } from "@wayne-zhang/ovault-evm"
132
+ ```
133
+
134
+ `trackOVaultSyncTransaction(txHash, { sourceChain, hubChain, dstChain }, withdrawalInfo?)`
135
+
136
+ If you are tracking withdrawals where multiple messages may exist, you can provide `withdrawalInfo` (`OVaultWithdrawalInfo`) so the tracker can pick the correct message index.
137
+
138
+ ## Development
139
+
140
+ - **Build/typecheck**: `npm run -s sdk:build`
141
+ - **Run SDK tests**: `npm run -s sdk:test`