-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add zksync oapp and oft #1181
Open
St0rmBr3w
wants to merge
9
commits into
main
Choose a base branch
from
feat/add-zksync-oapp-and-oft
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,274
−256
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
20dba45
fix: bump solana/web3.js version to 1.95.8
St0rmBr3w 0b67667
chore: add oapp and oft zksolc examples
St0rmBr3w eee4b3c
chore: update lockfile
St0rmBr3w c23f358
chore: update pnpm-lockfile
St0rmBr3w b4153f1
chore: add changeset
St0rmBr3w 6a53fbc
chore: fix: pnpm lockfile
St0rmBr3w aa33418
chore: fix: pnpm lockfile
St0rmBr3w fc6f0d6
chore: fix: pnpm lockfile
St0rmBr3w c0085e2
chore: update lockfile
St0rmBr3w File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"create-lz-oapp": minor | ||
--- | ||
|
||
Adding zksolc oapp and oft examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- | ||
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ | ||
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' | ||
# | ||
# Example environment configuration | ||
# | ||
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.- | ||
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ | ||
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' | ||
|
||
# By default, the examples support both mnemonic-based and private key-based authentication | ||
# | ||
# You don't need to set both of these values, just pick the one that you prefer and set that one | ||
MNEMONIC= | ||
PRIVATE_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
artifacts | ||
cache | ||
dist | ||
node_modules | ||
out | ||
*.log | ||
*.sol | ||
*.yaml | ||
*.lock | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require('@rushstack/eslint-patch/modern-module-resolution'); | ||
|
||
module.exports = { | ||
extends: ['@layerzerolabs/eslint-config-next/recommended'], | ||
rules: { | ||
// @layerzerolabs/eslint-config-next defines rules for turborepo-based projects | ||
// that are not relevant for this particular project | ||
'turbo/no-undeclared-env-vars': 'off', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
node_modules | ||
.env | ||
coverage | ||
coverage.json | ||
typechain | ||
typechain-types | ||
|
||
# Hardhat files | ||
cache | ||
artifacts | ||
artifacts-zk | ||
|
||
|
||
# LayerZero specific files | ||
.layerzero | ||
|
||
# foundry test compilation files | ||
out | ||
|
||
# pnpm | ||
pnpm-error.log | ||
|
||
# Editor and OS files | ||
.DS_Store | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v18.18.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
artifacts/ | ||
cache/ | ||
dist/ | ||
node_modules/ | ||
out/ | ||
*.log | ||
*ignore | ||
*.yaml | ||
*.lock | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
...require('@layerzerolabs/prettier-config-next'), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# @layerzerolabs/onft721-zksync-example | ||
|
||
## 1.0.3 | ||
|
||
### Patch Changes | ||
|
||
- ce03876: Get latest EndpointIds by bumping lz-definitions | ||
|
||
## 1.0.2 | ||
|
||
### Patch Changes | ||
|
||
- 1d2abff: new SDK methods, tests in devtools-ton, upgraded lz-definitions | ||
|
||
## 1.0.1 | ||
|
||
### Patch Changes | ||
|
||
- 1bb0524: Upgraded dependency (@layerzerolabs/lz-definitions 3.0.12->3.0.21) | ||
|
||
## 1.0.0 | ||
|
||
### Major Changes | ||
|
||
- fc1bc2f: adds a zkSolc compiler friendly example of ONFT721 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<p align="center"> | ||
<a href="https://layerzero.network"> | ||
<img alt="LayerZero" style="width: 400px" src="https://docs.layerzero.network/img/LayerZero_Logo_White.svg"/> | ||
</a> | ||
</p> | ||
|
||
<p align="center"> | ||
<a href="https://layerzero.network" style="color: #a77dff">Homepage</a> | <a href="https://docs.layerzero.network/" style="color: #a77dff">Docs</a> | <a href="https://layerzero.network/developers" style="color: #a77dff">Developers</a> | ||
</p> | ||
|
||
<h1 align="center">ONFT721 Example</h1> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oapp-zksync example, not onft721 |
||
|
||
<p align="center"> | ||
<a href="https://docs.layerzero.network/v2/developers/evm/onft721/quickstart" style="color: #a77dff">Quickstart</a> | <a href="https://docs.layerzero.network/contracts/oapp-configuration" style="color: #a77dff">Configuration</a> | <a href="https://docs.layerzero.network/contracts/options" style="color: #a77dff">Message Execution Options</a> | <a href="https://docs.layerzero.network/contracts/endpoint-addresses" style="color: #a77dff">Endpoint Addresses</a> | ||
</p> | ||
|
||
<p align="center">Template project for getting started with LayerZero's <code>ONFT721</code> contract development using the zkSync zksolc compiler.</p> | ||
|
||
This repository is the zkSync `zksolc` version of the LayerZero ONFT CLI example. The code is compatible with `zksolc` and works out of the box by running `pnpm compile`, which uses the `zksolc` compiler. | ||
|
||
## Note on zkSync Elastic Chains and LayerZero | ||
|
||
Please note that deploying to zkSync requires using the `zksolc` compiler. Ensure that you have configured the network settings correctly in your `hardhat.config.ts` file for zkSync elastic chains by adding the `zksync` flag: | ||
|
||
```typescript | ||
networks: { | ||
'zksync-testnet': { | ||
eid: EndpointId.ZKSYNCSEP_V2_TESTNET, | ||
url: process.env.RPC_URL_ZKSYNCSEP || 'https://sepolia.era.zksync.dev', | ||
accounts, | ||
zksync: true, // This flag is crucial for zkSync networks | ||
ethNetwork: 'sepolia', // Use 'sepolia' to match the Ethereum network zkSync Sepolia is using | ||
verifyURL: 'https://explorer.sepolia.era.zksync.dev/contract_verification', // Adjusted API URL for zkSync Sepolia | ||
}, | ||
}, | ||
``` | ||
|
||
## 1) Developing Contracts | ||
|
||
#### Installing dependencies | ||
|
||
We recommend using `pnpm` as a package manager (but you can of course use a package manager of your choice): | ||
|
||
```bash | ||
pnpm install | ||
``` | ||
|
||
#### Compiling your contracts | ||
|
||
This project supports both `hardhat` and `forge` compilation. By default, the `compile` command will execute both: | ||
|
||
```bash | ||
pnpm compile | ||
``` | ||
|
||
If you prefer one over the other, you can use the tooling-specific commands: | ||
|
||
```bash | ||
pnpm compile:forge | ||
pnpm compile:hardhat | ||
``` | ||
|
||
Or adjust the `package.json` to for example remove `forge` build: | ||
|
||
```diff | ||
- "compile": "$npm_execpath run compile:forge && $npm_execpath run compile:hardhat", | ||
- "compile:forge": "forge build", | ||
- "compile:hardhat": "hardhat compile", | ||
+ "compile": "hardhat compile" | ||
``` | ||
|
||
#### Running tests | ||
|
||
Similarly to the contract compilation, we support both `hardhat` and `forge` tests. By default, the `test` command will execute both: | ||
|
||
```bash | ||
pnpm test | ||
``` | ||
|
||
If you prefer one over the other, you can use the tooling-specific commands: | ||
|
||
```bash | ||
pnpm test:forge | ||
pnpm test:hardhat | ||
``` | ||
|
||
Or adjust the `package.json` to for example remove `hardhat` tests: | ||
|
||
```diff | ||
- "test": "$npm_execpath test:forge && $npm_execpath test:hardhat", | ||
- "test:forge": "forge test", | ||
- "test:hardhat": "$npm_execpath hardhat test" | ||
+ "test": "forge test" | ||
``` | ||
|
||
## 2) Deploying Contracts | ||
|
||
Set up deployer wallet/account: | ||
|
||
- Rename `.env.example` -> `.env` | ||
- Choose your preferred means of setting up your deployer wallet/account: | ||
|
||
``` | ||
MNEMONIC="test test test test test test test test test test test junk" | ||
or... | ||
PRIVATE_KEY="0xabc...def" | ||
``` | ||
|
||
- Fund this address with the corresponding chain's native tokens you want to deploy to. | ||
|
||
To deploy your contracts to your desired blockchains, run the following command in your project's folder: | ||
|
||
```bash | ||
npx hardhat lz:deploy | ||
``` | ||
|
||
More information about available CLI arguments can be found using the `--help` flag: | ||
|
||
```bash | ||
npx hardhat lz:deploy --help | ||
``` | ||
|
||
By following these steps, you can focus more on creating innovative omnichain solutions and less on the complexities of cross-chain communication. | ||
|
||
<br></br> | ||
|
||
<p align="center"> | ||
Join our community on <a href="https://discord-layerzero.netlify.app/discord" style="color: #a77dff">Discord</a> | Follow us on <a href="https://twitter.com/LayerZero_Labs" style="color: #a77dff">Twitter</a> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.22; | ||
|
||
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; | ||
import { OApp, MessagingFee, Origin } from "@layerzerolabs/oapp-evm/contracts/oapp/OApp.sol"; | ||
import { MessagingReceipt } from "@layerzerolabs/oapp-evm/contracts/oapp/OAppSender.sol"; | ||
|
||
contract MyOApp is OApp { | ||
constructor(address _endpoint, address _delegate) OApp(_endpoint, _delegate) Ownable(_delegate) {} | ||
|
||
string public data = "Nothing received yet."; | ||
|
||
/** | ||
* @notice Sends a message from the source chain to a destination chain. | ||
* @param _dstEid The endpoint ID of the destination chain. | ||
* @param _message The message string to be sent. | ||
* @param _options Additional options for message execution. | ||
* @dev Encodes the message as bytes and sends it using the `_lzSend` internal function. | ||
* @return receipt A `MessagingReceipt` struct containing details of the message sent. | ||
*/ | ||
function send( | ||
uint32 _dstEid, | ||
string memory _message, | ||
bytes calldata _options | ||
) external payable returns (MessagingReceipt memory receipt) { | ||
bytes memory _payload = abi.encode(_message); | ||
receipt = _lzSend(_dstEid, _payload, _options, MessagingFee(msg.value, 0), payable(msg.sender)); | ||
} | ||
|
||
/** | ||
* @notice Quotes the gas needed to pay for the full omnichain transaction in native gas or ZRO token. | ||
* @param _dstEid Destination chain's endpoint ID. | ||
* @param _message The message. | ||
* @param _options Message execution options (e.g., for sending gas to destination). | ||
* @param _payInLzToken Whether to return fee in ZRO token. | ||
* @return fee A `MessagingFee` struct containing the calculated gas fee in either the native token or ZRO token. | ||
*/ | ||
function quote( | ||
uint32 _dstEid, | ||
string memory _message, | ||
bytes memory _options, | ||
bool _payInLzToken | ||
) public view returns (MessagingFee memory fee) { | ||
bytes memory payload = abi.encode(_message); | ||
fee = _quote(_dstEid, payload, _options, _payInLzToken); | ||
} | ||
|
||
/** | ||
* @dev Internal function override to handle incoming messages from another chain. | ||
* @dev _origin A struct containing information about the message sender. | ||
* @dev _guid A unique global packet identifier for the message. | ||
* @param payload The encoded message payload being received. | ||
* | ||
* @dev The following params are unused in the current implementation of the OApp. | ||
* @dev _executor The address of the Executor responsible for processing the message. | ||
* @dev _extraData Arbitrary data appended by the Executor to the message. | ||
* | ||
* Decodes the received payload and processes it as per the business logic defined in the function. | ||
*/ | ||
function _lzReceive( | ||
Origin calldata /*_origin*/, | ||
bytes32 /*_guid*/, | ||
bytes calldata payload, | ||
address /*_executor*/, | ||
bytes calldata /*_extraData*/ | ||
) internal override { | ||
data = abi.decode(payload, (string)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import assert from 'assert' | ||
|
||
import { type DeployFunction } from 'hardhat-deploy/types' | ||
|
||
// TODO declare your contract name here | ||
const contractName = 'MyOApp' | ||
|
||
const deploy: DeployFunction = async (hre) => { | ||
const { getNamedAccounts, deployments } = hre | ||
|
||
const { deploy } = deployments | ||
const { deployer } = await getNamedAccounts() | ||
|
||
assert(deployer, 'Missing named deployer account') | ||
|
||
console.log(`Network: ${hre.network.name}`) | ||
console.log(`Deployer: ${deployer}`) | ||
|
||
// This is an external deployment pulled in from @layerzerolabs/lz-evm-sdk-v2 | ||
// | ||
// @layerzerolabs/toolbox-hardhat takes care of plugging in the external deployments | ||
// from @layerzerolabs packages based on the configuration in your hardhat config | ||
// | ||
// For this to work correctly, your network config must define an eid property | ||
// set to `EndpointId` as defined in @layerzerolabs/lz-definitions | ||
// | ||
// For example: | ||
// | ||
// networks: { | ||
// fuji: { | ||
// ... | ||
// eid: EndpointId.AVALANCHE_V2_TESTNET | ||
// } | ||
// } | ||
const endpointV2Deployment = await hre.deployments.get('EndpointV2') | ||
|
||
const { address } = await deploy(contractName, { | ||
from: deployer, | ||
args: [ | ||
endpointV2Deployment.address, // LayerZero's EndpointV2 address | ||
deployer, // owner | ||
], | ||
log: true, | ||
skipIfAlreadyDeployed: false, | ||
}) | ||
|
||
console.log(`Deployed contract: ${contractName}, network: ${hre.network.name}, address: ${address}`) | ||
} | ||
|
||
deploy.tags = [contractName] | ||
|
||
export default deploy |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is examples/oapp-zksync but title says onft721