Skip to content

Commit

Permalink
feat: Add OFT example
Browse files Browse the repository at this point in the history
  • Loading branch information
janjakubnanista committed Nov 22, 2023
1 parent 32a99f4 commit 5951708
Show file tree
Hide file tree
Showing 18 changed files with 3,907 additions and 78 deletions.
5 changes: 5 additions & 0 deletions examples/oft/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require('@rushstack/eslint-patch/modern-module-resolution');

module.exports = {
extends: ['@layerzerolabs/eslint-config-next/recommended'],
};
16 changes: 16 additions & 0 deletions examples/oft/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
node_modules
.env
coverage
coverage.json
typechain
typechain-types

# Hardhat files
cache
artifacts

#foundry test compilation files
out

# yarn
yarn-error.log
3 changes: 3 additions & 0 deletions examples/oft/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('@layerzerolabs/prettier-config-next'),
};
27 changes: 27 additions & 0 deletions examples/oft/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<p align="center">
<a href="https://layerzero.network">
<img alt="LayerZero" style="max-width: 500px" src="https://d3a2dpnnrypp5h.cloudfront.net/bridge-app/lz.png"/>
</a>
</p>

<h1 align="center">@layerzerolabs/oft-example</h1>

## Template repository for getting started with LayerZero using either Hardhat or Foundry in one project.

### Getting Started

#### Using Foundry

```bash
forge install
forge build
forge test
```

#### Using Hardhat

```bash
yarn
npx hardhat compile
npx hardhat test
```
46 changes: 46 additions & 0 deletions examples/oft/contracts/YourOFT.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { OFT } from "@layerzerolabs/lz-evm-oapp-v2/contracts/standards/oft/OFT.sol";

contract YourOFT is OFT {
constructor(
string memory _name,
string memory _symbol,
uint8 _localDecimals,
address _endpoint
) OFT(_name, _symbol, _localDecimals, _endpoint) {}

// TODO In the event you wish to add custom logic to your OFT contract, uncomment these and alter any corresponding logic...

// @dev allows the quote functions to mock sending the actual values that would be sent in a send()/sendAndCall()
// function _debitView(
// uint256 _amountLD,
// uint256 _minAmountLD,
// uint32 /*_dstEid*/
// ) internal view virtual override returns (uint256) {
// uint256 amountLDSend = _removeDust(_amountLD);
// if (amountLDSend < _minAmountLD) revert AmountSlippage(amountLDSend, _minAmountLD);
//
// return amountLDSend;
// }

// @dev hook applied to debit tokens on the src chain
// function _debit(
// uint256 _amountLD,
// uint256 _minAmountLD,
// uint32 _dstEid
// ) internal virtual override returns (uint256) {
// uint256 amountLDSend = _debitView(_amountLD, _minAmountLD, _dstEid);
//
// _burn(msg.sender, amountLDSend);
// return amountLDSend;
// }

// @dev hook applied on the receipt of tokens on the dst chain
// function _credit(address _to, uint256 _amountLD, uint32 /*_srcEid*/) internal virtual override returns (uint256) {
// _mint(_to, _amountLD);
// return _amountLD;
// }
}
27 changes: 27 additions & 0 deletions examples/oft/deploy/YourOFT.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { type DeployFunction } from 'hardhat-deploy/types'

// TODO declare your contract name here
const contractName = 'YourOFT'

const deploy: DeployFunction = async (hre) => {
const { getNamedAccounts, deployments } = hre

const { deploy } = deployments
const { deployer } = await getNamedAccounts()

console.log(`Network: ${hre.network.name}`)
console.log(`Deployer: ${deployer}`)

const { address } = await deploy(contractName, {
from: deployer,
args: [],
log: true,
waitConfirmations: 3,
skipIfAlreadyDeployed: false,
})

console.log(`Deployed contract: ${contractName}, network: ${hre.network.name}, address: ${address}`)
}

module.exports.tags = [contractName]
export default deploy
8 changes: 8 additions & 0 deletions examples/oft/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[profile.default]
src = 'contracts'
out = 'out'
test = 'test/foundry'
cache_path = 'cache'
libs = ['node_modules', '../lib']

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
18 changes: 18 additions & 0 deletions examples/oft/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'hardhat-deploy'
import 'hardhat-contract-sizer'
import '@nomiclabs/hardhat-ethers'
import { HardhatUserConfig } from 'hardhat/types'

import './tasks/'

const config: HardhatUserConfig = {
solidity: '0.8.19',

namedAccounts: {
deployer: {
default: 0, // wallet address of index[0], of the mnemonic in .env
},
},
}

export default config
30 changes: 30 additions & 0 deletions examples/oft/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@layerzerolabs/oft-example",
"version": "0.0.1",
"private": true,
"license": "MIT",
"scripts": {
"compile": "npx hardhat compile",
"lint": "yarn lint:js && yarn lint:sol",
"lint:fix": "npx prettier --write . && solhint 'contracts/**/*.sol' --fix --noPrompt",
"lint:js": "npx eslint '**/*.js' && npx prettier --check .",
"lint:sol": "solhint 'contracts/**/*.sol'",
"test": "npx hardhat test --parallel"
},
"devDependencies": {
"@layerzerolabs/eslint-config-next": "^1.5.60",
"@layerzerolabs/lz-evm-oapp-v2": "latest",
"@layerzerolabs/prettier-config-next": "^1.5.60",
"@layerzerolabs/solhint-config": "^1.5.58",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@rushstack/eslint-patch": "^1.5.1",
"hardhat": "^2.19.0",
"hardhat-contract-sizer": "^2.10.0",
"hardhat-deploy": "^0.11.43",
"hardhat-deploy-ethers": "^0.4.1",
"prettier": "^3.0.3",
"solhint": "^4.0.0",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
}
}
1 change: 1 addition & 0 deletions examples/oft/solhint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@layerzerolabs/solhint-config');
21 changes: 21 additions & 0 deletions examples/oft/tasks/getSigners.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { task, types } from 'hardhat/config'
import { type ActionType } from 'hardhat/types'

// TODO Figure out a way so this doesnt need to be defined in two places
interface TaskArguments {
n: number
}

const action: ActionType<TaskArguments> = async (taskArgs, hre) => {
const signers = await hre.ethers.getSigners()
for (let i = 0; i < taskArgs.n; ++i) {
console.log(`${i}) ${signers[i].address}`)
}
}

task('getSigners', 'show the signers of the current mnemonic', action).addOptionalParam(
'n',
'how many to show',
3,
types.int
)
2 changes: 2 additions & 0 deletions examples/oft/tasks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './getSigners'
// TODO get rid of index.ts somehow so we only need to define it in one place
15 changes: 15 additions & 0 deletions examples/oft/test/foundry/OFT.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.15;

import { Test } from "forge-std/Test.sol";

contract YourOApp is Test {
function setUp() public {
//TODO
}

function test() public {
//TODO
}
}
13 changes: 13 additions & 0 deletions examples/oft/test/hardhat/OFT.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
describe.skip('OFT: ', function () {
before(async function () {
//TODO
})

beforeEach(async function () {
//TODO
})

it('OFT send', async function () {
//TODO
})
})
13 changes: 13 additions & 0 deletions examples/oft/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"exclude": ["node_modules"],
"include": ["deploy", "tasks", "hardhat.config.ts"],
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"resolveJsonModule": true
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"prepare": "husky install"
},
"workspaces": [
"examples/*",
"packages/*"
],
"devDependencies": {
Expand Down
6 changes: 5 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"compile": {
"outputs": ["artifacts/**", "cache/**"],
"dependsOn": ["^build"]
},
"build": {
"outputs": ["dist/**"],
"dependsOn": ["^build"]
"dependsOn": ["compile", "^build"]
},
"clean": {
"outputs": [],
Expand Down
Loading

0 comments on commit 5951708

Please sign in to comment.