Skip to content

Commit

Permalink
Added a deployment script.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanIliev545 committed Oct 9, 2024
1 parent 56cab53 commit 2110a23
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 3 deletions.
56 changes: 56 additions & 0 deletions contracts/deployment_scripts/testnet/layer2/002_deploy_zen_base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import {DeployFunction} from 'hardhat-deploy/types';
import { Receipt } from 'hardhat-deploy/dist/types';
import { network } from 'hardhat';

/*
This script deploys the ZenTestnet contract on the l2 and whitelists it.
*/


const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const l2Network = hre;

const l2Accounts = await l2Network.getNamedAccounts();

const networkConfig = await l2Network.network.provider.request({
method: "net_config",
});

console.log(`net-cfg: ${JSON.stringify(networkConfig, null, " ")}`);

const zenTestnet = await l2Network.deployments.deploy("ZenTestnet", {
from: l2Accounts.deployer,
log: true,
args: [],
proxy: {
proxyContract: "OpenZeppelinTransparentProxy",
execute: {
init: {
methodName: "initialize",
args: [networkConfig["TransactionPostProcessorAddress"]]
}
}
}
});
console.log(`ZenBase deployed at ${zenTestnet.address}`);

const signer = await l2Network.ethers.getSigner(l2Accounts.deployer);
const transactionPostProcessor = await l2Network.ethers.getContractAt(
'TransactionPostProcessor',
networkConfig["TransactionPostProcessorAddress"],
signer
);

// TODO: add callback with the security epic when we add the EOA config and all the rules for access
// to system contracts
/*
const receipt = await transactionPostProcessor.addOnBlockEndCallback(zenTestnet.address);
if (receipt.status !== 1) {
throw new Error("Failed to register Zen token as a system callback");
}
console.log(`Callback added at ${receipt.transactionHash}`); */
}
export default func;
func.tags = ['ZenBase', 'ZenBase_deploy'];
func.dependencies = ['EthereumBridge'];
66 changes: 66 additions & 0 deletions contracts/src/zen/ZenTestnet.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SPDX-License-Identifier: Apache 2
pragma solidity ^0.8.0;

/*
// Import OpenZeppelin Contracts
import "../system/TransactionDecoder.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
*/

import "../system/OnBlockEndCallback.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";




interface ITransactionDecoder {
function recoverSender(Structs.Transaction calldata txData) external view returns (address sender);
}

/**
* @title ZenBase
* @dev ERC20 Token with minting functionality.
*/
contract ZenTestnet is Initializable, OnBlockEndCallback, ERC20Upgradeable, OwnableUpgradeable {
using Structs for Structs.Transaction;

event TransactionProcessed(address sender, uint256 amount);
/**
* @dev Constructor that gives msg.sender all of existing tokens.
* You can customize the initial supply as needed.
*/
constructor() {
_disableInitializers();
}

function initialize(address transactionPostProcessor) external initializer {
require(transactionPostProcessor != address(0), "Invalid transaction analyzer address");
__ERC20_init("Zen", "ZEN");
__Ownable_init(msg.sender);
_caller = transactionPostProcessor;
}


address private _caller;

modifier onlyCaller() {
require(msg.sender == _caller, "Caller: caller is not the designated address");
_;
}

function onBlockEnd(Structs.Transaction[] calldata transactions) external onlyCaller {
if (transactions.length == 0) {
revert("No transactions to convert");
}
// Implement custom logic here
for (uint256 i=0; i<transactions.length; i++) {
// Process transactions
_mint(transactions[i].from, 1);
emit TransactionProcessed(transactions[i].from, 1);
}
}
}
7 changes: 4 additions & 3 deletions tools/walletextension/rpcapi/net_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ func (api *NetAPI) Version(ctx context.Context) (*string, error) {
}

type ConfigResponseJson struct {
ManagementContractAddress string
MessageBusAddress string
L2MessageBusAddress string
ManagementContractAddress string
MessageBusAddress string
L2MessageBusAddress string
TransactionPostProcessorAddress string
}

func (api *NetAPI) Config(ctx context.Context) (*ConfigResponseJson, error) {
Expand Down

0 comments on commit 2110a23

Please sign in to comment.