Skip to content

Commit bf13fc8

Browse files
committed
refactor: reorganize utility functions and remove unused contracts
1 parent f78e7b6 commit bf13fc8

File tree

15 files changed

+165
-185
lines changed

15 files changed

+165
-185
lines changed

constants/index.ts

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const CHAIN_CONFIG = {
4646
},
4747
} as const;
4848

49-
// Some LayerZero error codes
49+
// LayerZero error codes
5050
// https://docs.layerzero.network/v2/developers/evm/create-lz-oapp/debugging
5151
export const LZ_ERRORS = {
5252
"0xf6ff4fb7":
@@ -69,53 +69,3 @@ export const NETWORK_NAMES = {
6969
"ETHERLINK-TESTNET": "etherlink-testnet",
7070
"ETHERLINK-MAINNET": "etherlink-mainnet",
7171
} as const;
72-
73-
// Helper function to determine if a network is mainnet
74-
export function isMainnet(network: string): boolean {
75-
return network === NETWORK_NAMES.ETHEREUM || network === NETWORK_NAMES["ETHERLINK-MAINNET"];
76-
}
77-
78-
// Helper function to get corresponding network pair
79-
export function getNetworkPair(network: string): { sourceNetwork: string; targetNetwork: string } {
80-
const mainnet = isMainnet(network);
81-
return {
82-
sourceNetwork: mainnet ? NETWORK_NAMES.ETHEREUM : NETWORK_NAMES.SEPOLIA,
83-
targetNetwork: mainnet ? NETWORK_NAMES["ETHERLINK-MAINNET"] : NETWORK_NAMES["ETHERLINK-TESTNET"],
84-
};
85-
}
86-
87-
// Helper function to get LZ endpoint by network name
88-
export function getLzEndpoint(network: string): string {
89-
const key = Object.entries(NETWORK_NAMES).find(([_, value]) => value === network)?.[0];
90-
if (!key || !CHAIN_CONFIG[key as keyof typeof CHAIN_CONFIG]) {
91-
throw new Error(`No LayerZero endpoint found for network: ${network}`);
92-
}
93-
return CHAIN_CONFIG[key as keyof typeof CHAIN_CONFIG].lzEndpointOnCurrentChain;
94-
}
95-
96-
// Helper function to get LZ EID by network name
97-
export function getLzEId(network: string): number {
98-
const key = Object.entries(NETWORK_NAMES).find(([_, value]) => value === network)?.[0];
99-
if (!key || !CHAIN_CONFIG[key as keyof typeof CHAIN_CONFIG]) {
100-
throw new Error(`No LayerZero EID found for network: ${network}`);
101-
}
102-
return CHAIN_CONFIG[key as keyof typeof CHAIN_CONFIG].lzEndpointIdOnCurrentChain;
103-
}
104-
105-
// Helper function to get pathway configuration
106-
export function getPathwayConfig(srcNetwork: string, destNetwork: string) {
107-
const srcKey = Object.entries(NETWORK_NAMES).find(([_, value]) => value === srcNetwork)?.[0];
108-
const destKey = Object.entries(NETWORK_NAMES).find(([_, value]) => value === destNetwork)?.[0];
109-
110-
if (!srcKey || !destKey || !CHAIN_CONFIG[srcKey as keyof typeof CHAIN_CONFIG]) {
111-
throw new Error(`Invalid network configuration for ${srcNetwork} -> ${destNetwork}`);
112-
}
113-
114-
const srcConfig = CHAIN_CONFIG[srcKey as keyof typeof CHAIN_CONFIG];
115-
const destConfig = CHAIN_CONFIG[destKey as keyof typeof CHAIN_CONFIG];
116-
117-
return {
118-
...srcConfig,
119-
lzEndpointIdOnRemoteChain: destConfig.lzEndpointIdOnCurrentChain,
120-
};
121-
}

contracts/Lock.sol

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

hardhat.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import "./tasks/setConfig";
1515
import "./tasks/setEnforcedOptions";
1616
import "./tasks/setOFTAdapterPeer";
1717
import "./tasks/setOFTPeer";
18+
import "./tasks/setupBridge";
1819
import "./tasks/verify";
1920

2021
// Load environment variables from .env file

tasks/deployOFT.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from "fs";
22
import { task } from "hardhat/config";
33
import { HardhatRuntimeEnvironment } from "hardhat/types";
44

5-
import { getLzEndpoint } from "../constants";
5+
import { getLzEndpoint } from "../utils";
66

77
interface ContractsJson {
88
oft?: string;

tasks/deployOFTAdapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { task } from "hardhat/config";
22
import { HardhatRuntimeEnvironment } from "hardhat/types";
33

4-
import { getLzEndpoint } from "../constants";
4+
import { getLzEndpoint } from "../utils";
55

66
task("deploy-oft-adapter", "Deploys the OFTAdapter contract")
77
.addParam("token", "The ERC20 token address")

tasks/lock.ts

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

tasks/sendOFT.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import * as fs from "fs";
55
import { task } from "hardhat/config";
66
import { HardhatRuntimeEnvironment } from "hardhat/types";
77

8-
import { LZ_ERRORS, getLzEId, getNetworkPair, isMainnet } from "../constants";
8+
import { LZ_ERRORS } from "../constants";
9+
import { getLzEId, getNetworkPair, isMainnet } from "../utils";
910

1011
const OFTAdapter_CONTRACT_NAME = "MyOFTAdapter";
1112

tasks/sendOFTBack.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import * as fs from "fs";
55
import { task } from "hardhat/config";
66
import { HardhatRuntimeEnvironment } from "hardhat/types";
77

8-
import { LZ_ERRORS, getLzEId, getNetworkPair, isMainnet } from "../constants";
8+
import { LZ_ERRORS } from "../constants";
9+
import { getLzEId, getNetworkPair, isMainnet } from "../utils";
910

1011
const OFT_CONTRACT_NAME = "MyOFT";
1112

tasks/setConfig.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as fs from "fs";
33
import { task } from "hardhat/config";
44
import { HardhatRuntimeEnvironment } from "hardhat/types";
55

6-
import { getNetworkPair, getPathwayConfig, isMainnet } from "../constants";
6+
import { getNetworkPair, getPathwayConfig, isMainnet } from "../utils";
77

88
const lzEndpointSetConfigABI = [
99
{
@@ -47,28 +47,6 @@ const lzEndpointSetConfigABI = [
4747
type: "function",
4848
},
4949
];
50-
51-
// LayerZero v2 Send/Receive Library addresses
52-
// https://docs.layerzero.network/v2/developers/evm/technical-reference/deployed-contracts
53-
const LZ_LIBRARIES = {
54-
ETHEREUM: {
55-
SEND: "0xbB2Ea70C9E858123480642Cf96acbcCE1372dCe1",
56-
RECEIVE: "0xc02Ab410f0734EFa3F14628780e6e695156024C2",
57-
},
58-
SEPOLIA: {
59-
SEND: "0x9A84c0dC1f58C75bF1db19621bbB5a1642A91217",
60-
RECEIVE: "0x9C44Ec2656bc6D6B9E47A07ac701c61bBEF5132A",
61-
},
62-
"ETHERLINK-TESTNET": {
63-
SEND: "0xE62d066e71fcA410eD48ad2f2A5A860443C04035",
64-
RECEIVE: "0x2072a32Df77bAE5713853d666f26bA5e47E54717",
65-
},
66-
"ETHERLINK-MAINNET": {
67-
SEND: "0xc1B621b18187F74c8F6D52a6F709Dd2780C09821",
68-
RECEIVE: "0x2072a32Df77bAE5713853d666f26bA5e47E54717",
69-
},
70-
} as const;
71-
7250
interface ContractsJson {
7351
oft?: string;
7452
oftAdapter?: string;
@@ -77,11 +55,11 @@ interface ContractsJson {
7755
}
7856

7957
task("set-config", "Sets LayerZero configuration for OFT or OFTAdapter contract")
80-
.addParam("isForOftAdapter", "Whether to set config for OFTAdapter (true) or OFT (false)")
58+
.addFlag("isForOftAdapter", "Whether to set config for OFTAdapter (true) or OFT (false)")
8159
.setAction(async (taskArgs, hre: HardhatRuntimeEnvironment) => {
8260
try {
8361
const network = hre.network.name;
84-
const isForOftAdapter = taskArgs.isForOftAdapter.toLowerCase() === "true";
62+
const isForOftAdapter = taskArgs.isForOftAdapter;
8563

8664
// Get network configuration
8765
const mainnet = isMainnet(network);

tasks/setEnforcedOptions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as fs from "fs";
33
import { task } from "hardhat/config";
44
import { HardhatRuntimeEnvironment } from "hardhat/types";
55

6-
import { NETWORK_NAMES, getLzEId, getNetworkPair, isMainnet } from "../constants";
6+
import { getLzEId, getNetworkPair, isMainnet } from "../utils";
77

88
interface ContractsJson {
99
oft?: string;
@@ -20,12 +20,12 @@ const DEFAULT_GAS_SETTINGS = {
2020
} as const;
2121

2222
task("set-enforced-options", "Sets enforced options for OFT or OFTAdapter contract")
23-
.addParam("isForOftAdapter", "Whether to set options for OFTAdapter (true) or OFT (false)")
23+
.addFlag("isForOftAdapter", "Whether to set options for OFTAdapter (true) or OFT (false)")
2424
.addOptionalParam("maxGas", "Max gas for executor lz receive option", DEFAULT_GAS_SETTINGS.testnet.toString())
2525
.setAction(async (taskArgs, hre: HardhatRuntimeEnvironment) => {
2626
try {
2727
const network = hre.network.name;
28-
const isForOftAdapter = taskArgs.isForOftAdapter.toLowerCase() === "true";
28+
const isForOftAdapter = taskArgs.isForOftAdapter;
2929
const maxGas = parseInt(taskArgs.maxGas);
3030

3131
// Get network configuration

0 commit comments

Comments
 (0)