Skip to content

Commit c39c35e

Browse files
shankars99TRileySchwarzSt0rmBr3w
committed
ovault - example improvements and deploy (#1656)
Signed-off-by: shankar <shankar@layerzerolabs.org> Co-authored-by: Blockchain Warlock <39101443+TRileySchwarz@users.noreply.github.com> Co-authored-by: Krak <krak@layerzerolabs.org>
1 parent 7d81c25 commit c39c35e

17 files changed

Lines changed: 412 additions & 352 deletions

examples/ovault-evm/README.md

Lines changed: 100 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -80,107 +80,137 @@ PRIVATE_KEY="YOUR_PRIVATE_KEY_HERE"
8080

8181
### 2. Network Configuration
8282

83-
Update `hardhat.config.ts` to include your desired networks with required `ovault` configuration. Each network needs an `ovault` config object specifying which contracts to deploy and token details.
84-
85-
> **Note**: If your asset is already an OFT, you do not need to deploy a separate mesh. The only requirement is that the asset OFT supports the hub chain you are deploying to.
83+
Update `hardhat.config.ts` to include your desired networks:
8684

8785
```typescript
8886
const config: HardhatUserConfig = {
8987
networks: {
9088
base: {
91-
eid: EndpointId.BASE_V2_MAINNET,
92-
url: process.env.RPC_URL_BASE || "https://base.gateway.tenderly.co",
89+
eid: EndpointId.BASESEP_V2_TESTNET,
90+
url:
91+
process.env.RPC_URL_BASESEP_TESTNET ||
92+
"https://base-sepolia.gateway.tenderly.co",
9393
accounts,
94-
ovault: {
95-
isHubChain: true,
96-
assetToken: {
97-
name: "MyAssetOFT",
98-
symbol: "ASSET",
99-
},
100-
shareToken: {
101-
name: "MyShareOFT",
102-
symbol: "SHARE",
103-
},
104-
},
10594
},
10695
arbitrum: {
107-
eid: EndpointId.ARBITRUM_V2_MAINNET,
108-
url: process.env.RPC_URL_ARB || "https://arbitrum.gateway.tenderly.co",
96+
eid: EndpointId.ARBSEP_V2_TESTNET,
97+
url:
98+
process.env.RPC_URL_ARBSEP_TESTNET ||
99+
"https://arbitrum-sepolia.gateway.tenderly.co",
109100
accounts,
110-
ovault: {
111-
isHubChain: false,
112-
assetToken: {
113-
name: "MyAssetOFT",
114-
symbol: "ASSET",
115-
},
116-
shareToken: {
117-
name: "MyShareOFT",
118-
symbol: "SHARE",
119-
},
120-
},
121101
},
122102
optimism: {
123-
eid: EndpointId.OPTIMISM_V2_MAINNET,
103+
eid: EndpointId.OPTSEP_V2_TESTNET,
124104
url:
125-
process.env.RPC_URL_OPTIMISM || "https://optimism.gateway.tenderly.co",
105+
process.env.RPC_URL_OPTSEP_TESTNET ||
106+
"https://optimism-sepolia.gateway.tenderly.co",
126107
accounts,
127-
ovault: {
128-
assetToken: {
129-
name: "MyAssetOFT",
130-
symbol: "ASSET",
131-
},
132-
},
133108
},
134109
},
135110
// ... rest of config
136111
};
137112
```
138113

114+
### 3. Deployment Configuration
115+
116+
Configure your vault deployment in `devtools/deployConfig.ts`. This file controls which chains get which contracts and their deployment settings:
117+
118+
> **Note**: If your asset is already an OFT, you do not need to deploy a separate mesh. The only requirement is that the asset OFT supports the hub chain you are deploying to.
119+
139120
Asset and share token networks don't need to perfectly overlap. Configure based on your requirements:
140121

141-
- `asset` tag requires `assetToken` config
142-
- `ovault` tag requires `isHubChain: true` and `shareToken` config
143-
- `share` tag requires `isHubChain: false` and `shareToken` config
122+
```typescript
123+
import { EndpointId } from "@layerzerolabs/lz-definitions";
144124

145-
## Build
125+
export const DEPLOYMENT_CONFIG = {
126+
// Vault chain configuration (where the ERC4626 vault lives)
127+
vault: {
128+
eid: EndpointId.ARBSEP_V2_TESTNET, // Your hub chain
129+
contracts: {
130+
vault: "MyERC4626",
131+
shareAdapter: "MyShareOFTAdapter",
132+
composer: "MyOVaultComposer",
133+
},
134+
// IF YOU HAVE A PRE-DEPLOYED ASSET, SET THE ADDRESS HERE
135+
assetAddress: undefined, // Set to '0x...' to use existing asset
136+
},
146137

147-
Compile your contracts:
138+
// Asset OFT configuration (deployed on all chains)
139+
asset: {
140+
contract: "MyAssetOFT",
141+
metadata: {
142+
name: "MyAssetOFT",
143+
symbol: "ASSET",
144+
},
145+
chains: [
146+
EndpointId.OPTSEP_V2_TESTNET,
147+
EndpointId.BASESEP_V2_TESTNET,
148+
EndpointId.ARBSEP_V2_TESTNET, // Include hub chain
149+
],
150+
},
148151

149-
```bash
150-
pnpm compile
152+
// Share OFT configuration (only on spoke chains)
153+
share: {
154+
contract: "MyShareOFT",
155+
metadata: {
156+
name: "MyShareOFT",
157+
symbol: "SHARE",
158+
},
159+
chains: [
160+
EndpointId.OPTSEP_V2_TESTNET,
161+
EndpointId.BASESEP_V2_TESTNET,
162+
// Do NOT include hub chain (it uses ShareOFTAdapter)
163+
],
164+
},
165+
};
151166
```
152167

153-
> **Testing Note**: If you're deploying the asset OFT from scratch for testing purposes, you'll need to mint an initial supply. Uncomment the `_mint` line in the `MyAssetOFT` constructor to provide initial liquidity. This ensures you have tokens to test deposit and cross-chain transfer functionality.
154-
>
155-
> **⚠️ Warning**: Do NOT mint share tokens directly in `MyShareOFT`. Share tokens must only be minted by the vault contract during deposits to maintain the correct share-to-asset ratio. Manually minting share tokens breaks the vault's accounting and can lead to incorrect redemption values. The mint line in `MyShareOFT` should only be uncommented for UI/integration testing, never in production.
168+
**Key Configuration Points:**
156169

157-
## Deploy
170+
- **Hub Chain**: Set `vault.eid` to your chosen hub chain's endpoint ID
171+
- **Asset Chains**: Include all chains where you want asset OFTs (including the hub chain)
172+
- **Share Chains**: Include only spoke chains (exclude hub, which uses the ShareOFTAdapter)
173+
- **Pre-deployed Asset**: Set `vault.assetAddress` if using an existing asset token
174+
175+
The deployment scripts automatically determine what to deploy based on:
176+
177+
- Vault contracts (ERC4626, ShareOFTAdapter, Composer) deploy only on the hub chain
178+
- Asset OFTs deploy on chains listed in `asset.chains` (unless using pre-deployed asset)
179+
- Share OFTs deploy on chains listed in `share.chains`
158180

159-
### 1. Deploy Asset OFTs
181+
## Build
160182

161-
Deploy Asset OFTs to networks with `assetToken` configuration:
183+
Compile your contracts:
162184

163185
```bash
164-
pnpm hardhat lz:deploy --tags asset
186+
pnpm compile`
165187
```
166188

167-
### 2. Deploy ERC4626 Vault System (Hub Chain Only)
189+
> **Testing Note**: If you're deploying the asset OFT from scratch for testing purposes, you'll need to mint an initial supply. Uncomment the `_mint` line in the `MyAssetOFT` constructor to provide initial liquidity. This ensures you have tokens to test deposit and cross-chain transfer functionality.
190+
>
191+
> **⚠️ Warning**: Do NOT mint share tokens directly in `MyShareOFT`. Share tokens must only be minted by the vault contract during deposits to maintain the correct share-to-asset ratio. Manually minting share tokens breaks the vault's accounting and can lead to incorrect redemption values. The mint line in `MyShareOFT` should only be uncommented for UI/integration testing, never in production.
168192
169-
Deploy the vault, composer, and ShareOFT adapter on networks with `isHubChain: true`:
193+
## Deploy
194+
195+
Deploy all vault contracts across all configured chains:
170196
171197
```bash
172-
pnpm hardhat lz:deploy --networks base --tags ovault
198+
pnpm hardhat lz:deploy --tags ovault
173199
```
174200
175-
### 3. Deploy Share OFTs (Spoke Chains Only)
201+
This single command will:
176202
177-
Deploy Share OFTs on networks with `isHubChain: false`:
203+
- Deploy `AssetOFTs` to all chains in `deployConfig.asset.chains`
204+
- Deploy the vault system (`ERC4626`, `ShareOFTAdapter`, `Composer`) on the hub chain
205+
- Deploy `ShareOFTs` to all spoke chains in `deployConfig.share.chains`
178206
179-
```bash
180-
pnpm hardhat lz:deploy --tags share
181-
```
207+
The deployment scripts automatically skip existing deployments, so you can safely run this command when expanding to new chains. Simply add the new chain endpoints to your `deployConfig.ts` and run the deploy command again.
182208
183-
The deploy scripts automatically validate your network configuration and will error if required config is missing or contracts are deployed on wrong chain types.
209+
> **Tip**: To deploy to specific networks only, use the `--networks` flag:
210+
>
211+
> ```bash
212+
> pnpm hardhat lz:deploy --tags ovault --networks arbitrum,optimism
213+
> ```
184214
185215
## Enable Messaging
186216
@@ -198,17 +228,17 @@ import {
198228
import { OAppEnforcedOption } from "@layerzerolabs/toolbox-hardhat";
199229
200230
const optimismContract: OmniPointHardhat = {
201-
eid: EndpointId.OPTIMISM_V2_MAINNET.valueOf(),
231+
eid: EndpointId.OPTSEP_V2_TESTNET.valueOf(),
202232
contractName: "MyAssetOFT",
203233
};
204234
205235
const arbitrumContract: OmniPointHardhat = {
206-
eid: EndpointId.ARBITRUM_V2_MAINNET.valueOf(),
236+
eid: EndpointId.ARBSEP_V2_TESTNET.valueOf(),
207237
contractName: "MyAssetOFT",
208238
};
209239
210240
const baseContract: OmniPointHardhat = {
211-
eid: EndpointId.BASE_V2_MAINNET.valueOf(),
241+
eid: EndpointId.BASESEP_V2_TESTNET.valueOf(),
212242
contractName: "MyAssetOFT",
213243
};
214244
@@ -287,17 +317,17 @@ import {
287317
import { OAppEnforcedOption } from "@layerzerolabs/toolbox-hardhat";
288318
289319
const optimismContract: OmniPointHardhat = {
290-
eid: EndpointId.OPTIMISM_V2_MAINNET.valueOf(),
320+
eid: EndpointId.OPTSEP_V2_TESTNET.valueOf(),
291321
contractName: "MyShareOFT", // Standard OFT (spoke)
292322
};
293323
294324
const arbitrumContract: OmniPointHardhat = {
295-
eid: EndpointId.BASE_V2_MAINNET.valueOf(), // Note: Base is the hub chain
325+
eid: EndpointId.BASESEP_V2_TESTNET.valueOf(), // Note: Base is the hub chain
296326
contractName: "MyShareOFTAdapter", // Adapter (hub/lockbox)
297327
};
298328
299329
const baseContract: OmniPointHardhat = {
300-
eid: EndpointId.ARBITRUM_V2_MAINNET.valueOf(),
330+
eid: EndpointId.ARBSEP_V2_TESTNET.valueOf(),
301331
contractName: "MyShareOFT", // Standard OFT (spoke)
302332
};
303333
@@ -366,9 +396,9 @@ To use different chains or network configurations:
366396
367397
**For Testnet Deployment:**
368398
369-
- Replace `EndpointId.OPTIMISM_V2_MAINNET` with `EndpointId.OPTSEP_V2_TESTNET`
370-
- Replace `EndpointId.BASE_V2_MAINNET` with `EndpointId.BASESEP_V2_TESTNET`
371-
- Replace `EndpointId.ARBITRUM_V2_MAINNET` with `EndpointId.ARBSEP_V2_TESTNET`
399+
- Replace `EndpointId.OPTSEP_V2_TESTNET` with `EndpointId.OPTSEP_V2_TESTNET`
400+
- Replace `EndpointId.BASESEP_V2_TESTNET` with `EndpointId.BASESEP_V2_TESTNET`
401+
- Replace `EndpointId.ARBSEP_V2_TESTNET` with `EndpointId.ARBSEP_V2_TESTNET`
372402
373403
**For Different Hub Chain:**
374404
@@ -380,7 +410,6 @@ To use different chains or network configurations:
380410
- Add pathway configurations between the new chain and existing chains
381411
- Deploy Asset OFTs and Share OFTs to the new chains
382412
383-
384413
### 4. Wire Asset OFT Network
385414
386415
Configure and wire the Asset OFT connections:
@@ -699,4 +728,4 @@ pnpm hardhat lz:deploy # Deploy contracts
699728

700729
---
701730

702-
**Need help?** Reach out in the [LayerZero Discord](https://discord-layerzero.netlify.app/discord) or check the [Developer Docs](https://docs.layerzero.network/).
731+
**Need help?** Reach out in the [LayerZero Discord](https://discord-layerzero.netlify.app/discord) or check the [Developer Docs](https://docs.layerzero.network/).

examples/ovault-evm/contracts/MyAssetOFT.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ contract MyAssetOFT is OFT {
3333
// This can be useful for testing or if the asset needs initial liquidity
3434
// _mint(msg.sender, 1 ether);
3535
}
36-
}
36+
}

examples/ovault-evm/contracts/MyShareOFT.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ contract MyShareOFT is OFT {
3636
// the correct relationship between shares and underlying assets
3737
// _mint(msg.sender, 1 ether); // ONLY uncomment for testing UI/integration, never in production
3838
}
39-
}
39+
}

examples/ovault-evm/deploy/MyAssetOFT.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)