Skip to content

Commit

Permalink
🗞️ upgradeable oft (#934)
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Goulding <[email protected]>
  • Loading branch information
ryandgoulding authored Nov 7, 2024
1 parent 41c3a28 commit a1abdc1
Show file tree
Hide file tree
Showing 98 changed files with 10,249 additions and 3,631 deletions.
15 changes: 15 additions & 0 deletions examples/oft-upgradeable/.env.example
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=
10 changes: 10 additions & 0 deletions examples/oft-upgradeable/.eslintignore
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
10 changes: 10 additions & 0 deletions examples/oft-upgradeable/.eslintrc.js
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',
},
};
24 changes: 24 additions & 0 deletions examples/oft-upgradeable/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
node_modules
.env
coverage
coverage.json
typechain
typechain-types

# Hardhat files
cache
artifacts


# LayerZero specific files
.layerzero

# foundry test compilation files
out

# pnpm
pnpm-error.log

# Editor and OS files
.DS_Store
.idea
1 change: 1 addition & 0 deletions examples/oft-upgradeable/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.18.0
10 changes: 10 additions & 0 deletions examples/oft-upgradeable/.prettierignore
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
3 changes: 3 additions & 0 deletions examples/oft-upgradeable/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('@layerzerolabs/prettier-config-next'),
};
528 changes: 528 additions & 0 deletions examples/oft-upgradeable/README.md

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions examples/oft-upgradeable/contracts/MyOFTAdapterUpgradeable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.22;

import { OFTAdapterUpgradeable } from "@layerzerolabs/oft-evm-upgradeable/contracts/oft/OFTAdapterUpgradeable.sol";

contract MyOFTAdapterUpgradeable is OFTAdapterUpgradeable {
constructor(address _token, address _lzEndpoint) OFTAdapterUpgradeable(_token, _lzEndpoint) {}

function initialize(address _delegate) public initializer {
__OFTAdapter_init(_delegate);
__Ownable_init(_delegate);
}
}
13 changes: 13 additions & 0 deletions examples/oft-upgradeable/contracts/MyOFTUpgradeable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.22;

import { OFTUpgradeable } from "@layerzerolabs/oft-evm-upgradeable/contracts/oft/OFTUpgradeable.sol";

contract MyOFTUpgradeable is OFTUpgradeable {
constructor(address _lzEndpoint) OFTUpgradeable(_lzEndpoint) {}

function initialize(string memory _name, string memory _symbol, address _delegate) public initializer {
__OFT_init(_name, _symbol, _delegate);
__Ownable_init(_delegate);
}
}
13 changes: 13 additions & 0 deletions examples/oft-upgradeable/contracts/mocks/MyERC20Mock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

// @dev WARNING: This is for testing purposes only
contract MyERC20Mock is ERC20 {
constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol) {}

function mint(address _to, uint256 _amount) public {
_mint(_to, _amount);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.22;

import { MyOFTAdapterUpgradeable } from "../MyOFTAdapterUpgradeable.sol";

// @dev WARNING: This is for testing purposes only
contract MyOFTAdapterUpgradeableMock is MyOFTAdapterUpgradeable {
constructor(address _token, address _lzEndpoint) MyOFTAdapterUpgradeable(_token, _lzEndpoint) {}
}
13 changes: 13 additions & 0 deletions examples/oft-upgradeable/contracts/mocks/MyOFTUpgradeableMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.22;

import { MyOFTUpgradeable } from "../MyOFTUpgradeable.sol";

// @dev WARNING: This is for testing purposes only
contract MyOFTUpgradeableMock is MyOFTUpgradeable {
constructor(address _lzEndpoint) MyOFTUpgradeable(_lzEndpoint) {}

function mint(address _to, uint256 _amount) public {
_mint(_to, _amount);
}
}
39 changes: 39 additions & 0 deletions examples/oft-upgradeable/deploy/MyOFTAdapterUpgradeable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { type DeployFunction } from 'hardhat-deploy/types'

const contractName = 'MyOFTAdapterUpgradeable'

const deploy: DeployFunction = async (hre) => {
const { deploy } = hre.deployments
const signer = (await hre.ethers.getSigners())[0]
console.log(`deploying ${contractName} on network: ${hre.network.name} with ${signer.address}`)

const endpointV2Deployment = await hre.deployments.get('EndpointV2')
try {
const proxy = await hre.ethers.getContract('MyOFTUpgradeable')
console.log(`Proxy: ${proxy.address}`)
} catch (e) {
console.log(`Proxy not found`)
}

await deploy(contractName, {
from: signer.address,
args: ['0x', endpointV2Deployment.address], // replace '0x' with the address of the ERC-20 token
log: true,
waitConfirmations: 1,
skipIfAlreadyDeployed: false,
proxy: {
checkABIConflict: false,
owner: signer.address,
execute: {
init: {
methodName: 'initialize',
args: [signer.address],
},
},
},
})
}

deploy.tags = [contractName]

export default deploy
35 changes: 35 additions & 0 deletions examples/oft-upgradeable/deploy/MyOFTUpgradeable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { type DeployFunction } from 'hardhat-deploy/types'

const contractName = 'MyOFTUpgradeable'

const deploy: DeployFunction = async (hre) => {
const { deploy } = hre.deployments
const signer = (await hre.ethers.getSigners())[0]
console.log(`deploying ${contractName} on network: ${hre.network.name} with ${signer.address}`)

const endpointV2Deployment = await hre.deployments.get('EndpointV2')
const existing = await hre.ethers.getContract('MyOFTUpgradeable')
console.log(`Proxy: ${existing.address}`)

await deploy(contractName, {
from: signer.address,
args: [endpointV2Deployment.address],
log: true,
waitConfirmations: 1,
skipIfAlreadyDeployed: false,
proxy: {
checkABIConflict: false,
owner: signer.address,
execute: {
init: {
methodName: 'initialize',
args: ['MyOFT', 'MOFT', signer.address], // TODO: add name/symbol
},
},
},
})
}

deploy.tags = [contractName]

export default deploy
27 changes: 27 additions & 0 deletions examples/oft-upgradeable/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[profile.default]
solc-version = '0.8.22'
src = 'contracts'
out = 'out'
test = 'test/foundry'
cache_path = 'cache/foundry'
libs = [
# We provide a set of useful contract utilities
# in the lib directory of @layerzerolabs/toolbox-foundry:
#
# - forge-std
# - ds-test
# - solidity-bytes-utils
'node_modules/@layerzerolabs/toolbox-foundry/lib',
'node_modules',
]

remappings = [
# Due to a misconfiguration of solidity-bytes-utils, an outdated version
# of forge-std is being dragged in
#
# To remedy this, we'll remap the ds-test and forge-std imports to ou own versions
'ds-test/=node_modules/@layerzerolabs/toolbox-foundry/lib/ds-test',
'forge-std/=node_modules/@layerzerolabs/toolbox-foundry/lib/forge-std',
'@layerzerolabs/=node_modules/@layerzerolabs/',
'@openzeppelin/=node_modules/@openzeppelin/',
]
82 changes: 82 additions & 0 deletions examples/oft-upgradeable/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Get the environment configuration from .env file
//
// To make use of automatic environment setup:
// - Duplicate .env.example file and name it .env
// - Fill in the environment variables
import 'dotenv/config'

import '@openzeppelin/hardhat-upgrades'
import 'hardhat-deploy'
import '@nomiclabs/hardhat-waffle'
import 'hardhat-deploy-ethers'
import 'hardhat-contract-sizer'
import '@nomiclabs/hardhat-ethers'
import '@layerzerolabs/toolbox-hardhat'

import { HardhatUserConfig, HttpNetworkAccountsUserConfig } from 'hardhat/types'

import { EndpointId } from '@layerzerolabs/lz-definitions'

// Set your preferred authentication method
//
// If you prefer using a mnemonic, set a MNEMONIC environment variable
// to a valid mnemonic
const MNEMONIC = process.env.MNEMONIC

// If you prefer to be authenticated using a private key, set a PRIVATE_KEY environment variable
const PRIVATE_KEY = process.env.PRIVATE_KEY

const accounts: HttpNetworkAccountsUserConfig | undefined = MNEMONIC
? { mnemonic: MNEMONIC }
: PRIVATE_KEY
? [PRIVATE_KEY]
: undefined

if (accounts == null) {
console.warn(
'Could not find MNEMONIC or PRIVATE_KEY environment variables. It will not be possible to execute transactions in your example.'
)
}

const config: HardhatUserConfig = {
paths: {
cache: 'cache/hardhat',
},
solidity: {
compilers: [
{
version: '0.8.22',
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
],
},
networks: {
'sepolia-testnet': {
eid: EndpointId.SEPOLIA_V2_TESTNET,
url: process.env.RPC_URL_SEPOLIA || 'https://rpc.sepolia.org/',
accounts,
},
'avalanche-testnet': {
eid: EndpointId.AVALANCHE_V2_TESTNET,
url: process.env.RPC_URL_FUJI || 'https://rpc.ankr.com/avalanche_fuji',
accounts,
},
'amoy-testnet': {
eid: EndpointId.AMOY_V2_TESTNET,
url: process.env.RPC_URL_AMOY || 'https://polygon-amoy-bor-rpc.publicnode.com',
accounts,
},
},
namedAccounts: {
deployer: {
default: 0, // wallet address of index[0], of the mnemonic in .env
},
},
}

export default config
60 changes: 60 additions & 0 deletions examples/oft-upgradeable/layerzero.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { EndpointId } from '@layerzerolabs/lz-definitions'

import type { OAppOmniGraphHardhat, OmniPointHardhat } from '@layerzerolabs/toolbox-hardhat'

const sepoliaContract: OmniPointHardhat = {
eid: EndpointId.SEPOLIA_V2_TESTNET,
contractName: 'MyOFT',
}

const fujiContract: OmniPointHardhat = {
eid: EndpointId.AVALANCHE_V2_TESTNET,
contractName: 'MyOFT',
}

const amoyContract: OmniPointHardhat = {
eid: EndpointId.AMOY_V2_TESTNET,
contractName: 'MyOFT',
}

const config: OAppOmniGraphHardhat = {
contracts: [
{
contract: fujiContract,
},
{
contract: sepoliaContract,
},
{
contract: amoyContract,
},
],
connections: [
{
from: fujiContract,
to: sepoliaContract,
},
{
from: fujiContract,
to: amoyContract,
},
{
from: sepoliaContract,
to: fujiContract,
},
{
from: sepoliaContract,
to: amoyContract,
},
{
from: amoyContract,
to: sepoliaContract,
},
{
from: amoyContract,
to: fujiContract,
},
],
}

export default config
Loading

0 comments on commit a1abdc1

Please sign in to comment.