Skip to content

Commit ef64afb

Browse files
committed
chore(script): oft send scripts
0 parents  commit ef64afb

11 files changed

+791
-0
lines changed

.env.example

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
ETHEREUM_RPC_URL="https://1rpc.io/eth"
2+
BASE_RPC_URL="https://mainnet.base.org"
3+
ARBITRUM_RPC_URL="YOUR_ARBITRUM_RPC_URL"
4+
5+
# Token Address on Ethereum
6+
erc20TokenAddress="0x33333333fede34409fb7f67c6585047e1f653333"
7+
# LayerZero EndPoint on Ethereum
8+
lzEndpointOnSrcChain=0x1a44076050125825900e736c501f859c50fE728c
9+
lzEndpointIdOnSrcChain=30101
10+
# LayerZero EndPoint on Base
11+
lzEndpointOnDestChain=0x1a44076050125825900e736c501f859c50fE728c
12+
lzEndpointIdOnDestChain=30184
13+
# Ethereum OFT Adapter Address
14+
oftAdapterContractAddress=0x5e1F75388dc768f6129b9ee859BFB1361631a77e
15+
# Base OFT Token Address
16+
oftContractAddress=0x333333C465a19C85f85c6CfbED7B16b0B26E3333
17+
18+
# No need to change
19+
executorLzReceiveOptionMaxGas=200000
20+
gasDropInWeiOnDestChain=0
21+
22+
# Bridge Token Account
23+
SENDER_ACCOUNT_PRIV_KEY=wallet_private_key
24+
RECEIVER_ACCOUNT_ADDRESS=wallet_address
25+
26+
# Token amount to send
27+
SEND_AMOUNT=1

.gitignore

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
node_modules
2+
.env
3+
4+
# Hardhat files
5+
/cache
6+
/artifacts
7+
8+
# TypeChain files
9+
/typechain
10+
/typechain-types
11+
12+
# solidity-coverage files
13+
/coverage
14+
/coverage.json
15+
16+
# Hardhat Ignition default folder for deployments against a local node
17+
ignition/deployments/chain-31337

README.md

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# OFT Bridge Script
2+
3+
## Overview
4+
5+
This project provides a simple example demonstrating how to send **OFT (Omnichain Fungible Tokens)** across different blockchain networks using scripts. You can use it to send tokens across chains or send back the OFT tokens to the origin chain. It supports transferring tokens between the mainnet and the Base network.
6+
7+
## Prerequisites
8+
9+
Before getting started, ensure you have the following tools installed:
10+
11+
- **Node.js** (recommended v16 or higher)
12+
- **Yarn** (a JavaScript package manager)
13+
14+
You can check if these are installed by running the following commands:
15+
16+
```bash
17+
node -v
18+
yarn -v
19+
```
20+
21+
If they're not installed, you can install them from [Node.js official website](https://nodejs.org/) and [Yarn official website](https://yarnpkg.com/).
22+
23+
## Installation
24+
25+
Follow these steps to set up the project on your local machine:
26+
27+
1. **Clone the Repository**
28+
29+
Run the following command to clone this repository to your local machine:
30+
31+
```bash
32+
git clone [email protected]:ora-io/oft-bridge-script.git
33+
cd oft-bridge-script
34+
```
35+
36+
2. **Install Dependencies**
37+
38+
Install the required dependencies using `Yarn`:
39+
40+
```bash
41+
yarn install
42+
```
43+
44+
3. **Copy the Environment Variables File**
45+
46+
In the root directory of the project, you'll find a `.env.example` file. Copy it and rename it to `.env`:
47+
48+
```bash
49+
cp .env.example .env
50+
```
51+
52+
4. **Fill in the Environment Variables**
53+
54+
Open the `.env` file and fill in the following required fields:
55+
- **{XXX}_RPC_URL**: The RPC URL of the network you want to use.
56+
- **SENDER_ACCOUNT_PRIV_KEY**: The private key of the sender account (used to sign the transaction).
57+
- **RECEIVER_ACCOUNT_ADDRESS**: The address of the receiving account.
58+
- **SEND_AMOUNT**: The amount of tokens to send. (if you want to send 1 ora coin, put 1 in here).
59+
60+
Example:
61+
62+
```env
63+
# Test bridge token
64+
SENDER_ACCOUNT_PRIV_KEY=your_wallet_private_key
65+
RECEIVER_ACCOUNT_ADDRESS=receiver_wallet_address
66+
67+
# Token amount to send
68+
SEND_AMOUNT=1
69+
```
70+
71+
## Usage
72+
73+
Once you've configured the environment variables, you can run the following commands to send OFT tokens across chains:
74+
75+
### Send Tokens to Base Network
76+
77+
To send OFT tokens from the mainnet to the Base network, run the following command:
78+
79+
```bash
80+
yarn run ora-eth-to-base
81+
```
82+
83+
This command will send the specified amount of tokens from the mainnet to the receiver address on the Base network.
84+
85+
### Send Tokens Back to Mainnet
86+
87+
To send OFT tokens back from the Base network to the origin chain (e.g., mainnet), run the following command:
88+
89+
```bash
90+
yarn run ora-base-to-eth
91+
```
92+
93+
This command will send the tokens back from the Base network to the mainnet.
94+
95+
## Important Notes
96+
97+
- Make sure that the private keys and addresses you are using are correct and secure.
98+
- Double-check the token amounts before sending to avoid sending incorrect values.
99+
- This script is intended for development and testing purposes. Please ensure proper validation and auditing before using it in a production environment.
100+
101+
## Common Issues
102+
103+
### How do I get my wallet private key?
104+
105+
Your wallet private key can typically be exported from the wallet you are using (e.g., MetaMask or other wallets). Make sure to keep the private key secure and do not expose it to anyone.
106+
107+
### How do I get my wallet address?
108+
109+
You can view your wallet address in your crypto wallet. Wallet addresses usually begin with `0x` followed by a string of characters.
110+
111+
### Does this support other networks?
112+
113+
Currently, this project supports the mainnet and the Base network. Additional blockchain networks may be supported in the future.
114+
115+
## Contributing
116+
117+
We welcome contributions! If you have any ideas, improvements, or bug fixes, feel free to submit a pull request. Before submitting, please ensure that all tests are run and the code is thoroughly validated.
118+
119+
## License
120+
121+
This project is licensed under the [MIT License](LICENSE), which allows you to freely use, modify, and distribute the code.
122+
123+
---
124+
125+
If you encounter any issues or have questions, please feel free to open an issue or reach out. We hope this tool helps you in your cross-chain token transfer needs!

hardhat.config.ts

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import "dotenv/config";
2+
import "@nomicfoundation/hardhat-toolbox";
3+
import "@nomicfoundation/hardhat-verify";
4+
5+
const ACCOUNTS = process.env.DEPLOYER_ACCOUNT_PRIV_KEY
6+
? [`${process.env.SENDER_BACK_ACCOUNT_PRIV_KEY}`]
7+
: [];
8+
9+
const ETHEREUM_RPC_URL = process.env.ETHEREUM_RPC_URL;
10+
const BASE_RPC_URL = process.env.BASE_RPC_URL;
11+
const ARBITRUM_RPC_URL = process.env.ARBITRUM_RPC_URL;
12+
13+
module.exports = {
14+
defaultNetwork: "hardhat",
15+
gasReporter: {
16+
enabled: false,
17+
},
18+
networks: {
19+
//hardhat: { chainId: 31337 },
20+
localhost: {
21+
chainId: 31337,
22+
url: "http://127.0.0.1:8545",
23+
accounts: ACCOUNTS,
24+
},
25+
polygon: {
26+
chainId: 137,
27+
url: "https://polygon-mainnet.public.blastapi.io", // "https://polygon-pokt.nodies.app",
28+
accounts: ACCOUNTS,
29+
},
30+
sepolia: {
31+
chainId: 11155111,
32+
url: "https://eth-sepolia.public.blastapi.io",
33+
accounts: ACCOUNTS,
34+
},
35+
ethereum: {
36+
chainId: 1,
37+
url: ETHEREUM_RPC_URL,
38+
accounts: ACCOUNTS,
39+
},
40+
base: {
41+
chainId: 8453,
42+
url: BASE_RPC_URL,
43+
accounts: ACCOUNTS,
44+
},
45+
avalanche: {
46+
chainId: 43114,
47+
url: "https://avalanche.drpc.org",
48+
accounts: ACCOUNTS,
49+
},
50+
arbitrum: {
51+
chainId: 42161,
52+
url: ARBITRUM_RPC_URL,
53+
accounts: ACCOUNTS,
54+
},
55+
},
56+
etherscan: {
57+
customChains: [
58+
{
59+
network: "bnbMainnet",
60+
chainId: 56,
61+
urls: {
62+
apiURL: "https://api.bscscan.com/api",
63+
browserURL: "https://bscscan.com",
64+
},
65+
},
66+
{
67+
network: "polygon",
68+
chainId: 137,
69+
urls: {
70+
apiURL: "https://api.polygonscan.com/api",
71+
browserURL: "https://polygonscan.com",
72+
},
73+
},
74+
{
75+
network: "ethereum",
76+
chainId: 1,
77+
urls: {
78+
apiURL: "https://api.etherscan.io/api",
79+
browserURL: "https://etherscan.io",
80+
},
81+
},
82+
{
83+
network: "fantom",
84+
chainId: 250,
85+
urls: {
86+
apiURL: "https://api.ftmscan.com/api",
87+
browserURL: "https://ftmscan.com",
88+
},
89+
},
90+
{
91+
network: "optimism",
92+
chainId: 10,
93+
urls: {
94+
apiURL: "https://api-optimistic.etherscan.io/api",
95+
browserURL: "https://optimistic.etherscan.io/",
96+
},
97+
},
98+
{
99+
network: "base",
100+
chainId: 8453,
101+
urls: {
102+
apiURL: "https://api.basescan.org/api",
103+
browserURL: "https://basescan.org",
104+
},
105+
},
106+
{
107+
network: "avalanche",
108+
chainId: 43114,
109+
urls: {
110+
apiURL: "https://api.avascan.info/v2/network/mainnet/evm/43114/etherscan",
111+
browserURL: "https://avascan.info",
112+
},
113+
},
114+
{
115+
network: "arbitrum",
116+
chainId: 42161,
117+
urls: {
118+
apiURL: "https://api.arbiscan.io/api",
119+
browserURL: "https://arbiscan.io",
120+
},
121+
},
122+
],
123+
},
124+
sourcify: {
125+
enabled: false,
126+
},
127+
solidity: {
128+
version: "0.8.22",
129+
settings: {
130+
evmVersion: "paris",
131+
optimizer: {
132+
enabled: true,
133+
runs: 200,
134+
},
135+
viaIR: true,
136+
},
137+
},
138+
paths: {
139+
sources: "./src",
140+
tests: "./test",
141+
cache: "./cache",
142+
artifacts: "./artifacts",
143+
},
144+
};

ignition/modules/Lock.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This setup uses Hardhat Ignition to manage smart contract deployments.
2+
// Learn more about it at https://hardhat.org/ignition
3+
4+
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
5+
6+
const JAN_1ST_2030 = 1893456000;
7+
const ONE_GWEI: bigint = 1_000_000_000n;
8+
9+
const LockModule = buildModule("LockModule", (m) => {
10+
const unlockTime = m.getParameter("unlockTime", JAN_1ST_2030);
11+
const lockedAmount = m.getParameter("lockedAmount", ONE_GWEI);
12+
13+
const lock = m.contract("Lock", [unlockTime], {
14+
value: lockedAmount,
15+
});
16+
17+
return { lock };
18+
});
19+
20+
export default LockModule;

package.json

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "oft-cc-script",
3+
"version": "1.0.0",
4+
"description": "oft-cc-script",
5+
"scripts": {
6+
"ora-eth-to-base": "npx hardhat run scripts/send_via_oft_adapter.ts --network ethereum",
7+
"ora-base-to-eth": "npx hardhat run scripts/send_via_oft.ts --network base"
8+
},
9+
"devDependencies": {
10+
"@ethersproject/bytes": "^5.7.0",
11+
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
12+
"@nomicfoundation/hardhat-ethers": "^3.0.0",
13+
"@nomicfoundation/hardhat-ignition": "^0.15.2",
14+
"@nomicfoundation/hardhat-ignition-ethers": "^0.15.0",
15+
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
16+
"@nomicfoundation/hardhat-verify": "^2.0.7",
17+
"@nomicfoundation/ignition-core": "^0.15.2",
18+
"@typechain/ethers-v6": "^0.5.0",
19+
"@typechain/hardhat": "^9.0.0",
20+
"@types/chai": "^4.2.0",
21+
"@types/mocha": ">=9.1.0",
22+
"@types/node": "^20.12.7",
23+
"chai": "^4.2.0",
24+
"ethers": "^6.12.1",
25+
"hardhat": "^2.22.3",
26+
"hardhat-gas-reporter": "^1.0.8",
27+
"rimraf": "^5.0.5",
28+
"solidity-coverage": "^0.8.1",
29+
"ts-node": "^10.9.2",
30+
"typechain": "^8.3.0",
31+
"typescript": "^5.4.5"
32+
},
33+
"dependencies": {
34+
"@ethersproject/abi": "^5.7.0",
35+
"@layerzerolabs/lz-evm-messagelib-v2": "^2.3.15",
36+
"@layerzerolabs/lz-evm-oapp-v2": "^2.3.15",
37+
"@layerzerolabs/lz-evm-protocol-v2": "^2.3.15",
38+
"@layerzerolabs/lz-v2-utilities": "2.3.15",
39+
"@layerzerolabs/oft-evm": "^3.0.0",
40+
"@layerzerolabs/scan-client": "^0.0.8",
41+
"@nomicfoundation/hardhat-network-helpers": "^1.0.9",
42+
"@openzeppelin/contracts": "^5.0.0",
43+
"dotenv": "^16.4.5"
44+
}
45+
}

0 commit comments

Comments
 (0)