Skip to content
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: simplify the omnichain template #134

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion contracts/OnlySystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,23 @@ pragma solidity ^0.8.7;
import "@zetachain/protocol-contracts/contracts/zevm/SystemContract.sol";

contract OnlySystem {
SystemContract internal systemContract;
mapping(uint256 => address) private systemContracts;

error OnlySystemContract(string);

modifier onlySystem(SystemContract systemContract) {
constructor() {
address _systemContractAddress = _initializeSystemContracts();
systemContract = SystemContract(_systemContractAddress);
}

function _initializeSystemContracts() private returns (address) {
systemContracts[7000] = 0x91d18e54DAf4F677cB28167158d6dd21F6aB3921;
systemContracts[7001] = 0xEdf1c3275d13489aCdC6cD6eD246E72458B8795B;
return systemContracts[block.chainid];
}

modifier onlySystem() {
if (msg.sender != address(systemContract)) {
revert OnlySystemContract(
"Only system contract can call this function"
Expand Down
12 changes: 12 additions & 0 deletions contracts/ZetaChainApp.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.7;

import "./OnlySystem.sol";
import "./BytesHelperLib.sol";
import "./SwapHelperLib.sol";
import "@zetachain/protocol-contracts/contracts/zevm/SystemContract.sol";
import "@zetachain/protocol-contracts/contracts/zevm/interfaces/IWZETA.sol";

abstract contract ZetaChainApp is zContract, OnlySystem {
constructor() OnlySystem() {}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.7;

import "@zetachain/protocol-contracts/contracts/zevm/SystemContract.sol";
import "@zetachain/protocol-contracts/contracts/zevm/interfaces/zContract.sol";
import "@zetachain/toolkit/contracts/OnlySystem.sol";
import "@zetachain/toolkit/contracts/ZetaChain.sol";

contract {{contractName}} is zContract, OnlySystem {
SystemContract public systemContract;

constructor(address systemContractAddress) {
systemContract = SystemContract(systemContractAddress);
}
contract {{contractName}} is ZetaChain {
constructor() ZetaChain() {}

function onCrossChainCall(
zContext calldata context,
address zrc20,
uint256 amount,
bytes calldata message
) external virtual override onlySystem(systemContract) {
) external override onlySystem {
{{#if arguments.pairsWithDataLocation}}
({{#each arguments.pairsWithDataLocation}}{{#if @index}}, {{/if}}{{this.[1]}} {{this.[0]}}{{/each}}) = abi.decode(
message,
Expand Down
4 changes: 1 addition & 3 deletions packages/tasks/templates/omnichain/tasks/deploy.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
);
}

const systemContract = getAddress("systemContract", network);

const factory = await hre.ethers.getContractFactory(args.name);
const contract = await factory.deploy(systemContract);
const contract = await factory.deploy();
await contract.deployed();

const isTestnet = network === "zeta_testnet";
Expand Down
2 changes: 2 additions & 0 deletions typechain-types/@openzeppelin/contracts/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* Autogenerated file. Do not edit manually. */
/* tslint:disable */
/* eslint-disable */
import type * as access from "./access";
export type { access };
import type * as token from "./token";
export type { token };
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
/* eslint-disable */
import type * as interfaces from "./interfaces";
export type { interfaces };
import type * as tools from "./tools";
export type { tools };
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/* eslint-disable */
import type * as zetaInterfacesSol from "./ZetaInterfaces.sol";
export type { zetaInterfacesSol };
export type { ZetaInteractorErrors } from "./ZetaInteractorErrors";
Loading
Loading