Skip to content

Commit

Permalink
chore: rename contract for compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ericlee42 committed Feb 27, 2024
1 parent 20df3d0 commit 7adc031
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 121 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Administrators can distribute rewards and update parameters related to reward di

Main contract code function introduction:

1. LockingManager: This contract is a main function contract, allowing users to lock tokens to apply to become a sequencer, receive rewards, unlock tokens to exit the sequencer, reward distribution, and other management functions can refer to the contract source code.
2. LockingEscrow: This contract keeps locked tokens by LockingManager
3. MetisSequencerSet: This contract controls blocks production
1. LockingPool: This contract is a main function contract, allowing users to lock tokens to apply to become a sequencer, receive rewards, unlock tokens to exit the sequencer, reward distribution, and other management functions can refer to the contract source code.
2. LockingInfo: This contract keeps locked tokens information for LockingPool
3. MetisSequencerSet: This contract controls blocks production on metis layer2

# Example

Expand Down
8 changes: 4 additions & 4 deletions contracts/LockingEscrow.sol → contracts/LockingInfo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

import {IL1ERC20Bridge} from "./interfaces/IL1ERC20Bridge.sol";
import {ILockingEscrow} from "./interfaces/ILockingEscrow.sol";
import {ILockingInfo} from "./interfaces/ILockingInfo.sol";
import {ISeqeuncerInfo} from "./interfaces/ISeqeuncerInfo.sol";

contract LockingEscrow is ILockingEscrow, OwnableUpgradeable {
contract LockingInfo is ILockingInfo, OwnableUpgradeable {
error NotManager();

using SafeERC20 for IERC20;
Expand Down Expand Up @@ -178,11 +178,11 @@ contract LockingEscrow is ILockingEscrow, OwnableUpgradeable {
emit UnlockInit(
_seq.signer,
_seqId,
reward,
_seq.nonce,
_seq.deactivationBatch,
_seq.deactivationTime,
_seq.unlockClaimTime,
reward
_seq.unlockClaimTime
);
}

Expand Down
52 changes: 12 additions & 40 deletions contracts/LockingManager.sol → contracts/LockingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ pragma solidity 0.8.20;

import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";

import {ILockingEscrow} from "./interfaces/ILockingEscrow.sol";
import {ILockingManager} from "./interfaces/ILockingManager.sol";
import {ILockingInfo} from "./interfaces/ILockingInfo.sol";
import {ILockingPool} from "./interfaces/ILockingPool.sol";

import {SeqeuncerInfo} from "./SeqeuncerInfo.sol";

contract LockingManager is ILockingManager, PausableUpgradeable, SeqeuncerInfo {
contract LockingPool is ILockingPool, PausableUpgradeable, SeqeuncerInfo {
error NotMpc();
error BFTFail();

Expand All @@ -19,7 +19,7 @@ contract LockingManager is ILockingManager, PausableUpgradeable, SeqeuncerInfo {
uint256 endEpoch; // end epoch number for current batch
}

ILockingEscrow public escorow;
ILockingInfo public escorow;

// delay time for unlock
uint256 public WITHDRAWAL_DELAY;
Expand All @@ -45,7 +45,7 @@ contract LockingManager is ILockingManager, PausableUpgradeable, SeqeuncerInfo {
endEpoch: 0
});

escorow = ILockingEscrow(_escorow);
escorow = ILockingInfo(_escorow);

__Pausable_init();
__LockingBadge_init();
Expand Down Expand Up @@ -96,49 +96,20 @@ contract LockingManager is ILockingManager, PausableUpgradeable, SeqeuncerInfo {

/**
* @dev updateSigner Allow sqeuencer to update new signers to replace old signer addresses,and NFT holder will be transfer driectly
* @param _seqId unique integer to identify a sequencer.
* @param _seqId the sequencer id
* @param _signerPubkey the new signer pubkey address
*/
function updateSigner(
uint256 _seqId,
bytes calldata _signerPubkey
) external whitelistRequired {
Sequencer storage seq = sequencers[_seqId];
if (seq.status != Status.Active) {
revert SeqNotActive();
}

// only update by the signer
address signer = seq.signer;
if (signer != msg.sender) {
revert NotSeqSigner();
}

require(_signerPubkey.length == 64, "invalid pubkey");
address newSigner = address(uint160(uint256(keccak256(_signerPubkey))));
require(newSigner != address(0), "empty address");

// the new signer should not be a signer before
if (seqSigners[newSigner] != 0) {
revert OwnedSigner();
}
seq.signer = newSigner;
seqSigners[newSigner] = _seqId;

// invalid it
seqSigners[signer] = type(uint256).max;

// set signer updating batch id
seq.updatingBatch = currentBatch.id;

uint256 nonce = seq.nonce + 1;
seq.nonce = nonce;

emit SignerChange(_seqId, signer, newSigner, nonce, _signerPubkey);
_updateSigner(_seqId, currentBatch.id, _signerPubkey);
}

/**
* @dev lockFor lock Metis and participate in the sequencer node
* the msg.sender will be owner of the seqeuncer
* the owner has abilities to leverage lock/relock/unlock/cliam
* @param _signer Sequencer signer address
* @param _amount Amount of L1 metis token to lock for.
* @param _signerPubkey Sequencer signer pubkey, it should be uncompressed
Expand All @@ -163,7 +134,7 @@ contract LockingManager is ILockingManager, PausableUpgradeable, SeqeuncerInfo {
owner: msg.sender,
signer: _signer,
pubkey: _signerPubkey,
rewardRecipient: address(0), // the recepient should be update afterward
rewardRecipient: address(0), // update it using `setSequencerRewardRecipient` after then
status: Status.Active
});

Expand Down Expand Up @@ -278,7 +249,7 @@ contract LockingManager is ILockingManager, PausableUpgradeable, SeqeuncerInfo {
delete seqOwners[seq.owner];

// invalid it
seqSigners[seq.signer] = type(uint256).max;
_invalidSignerAddress(seq.signer);

escorow.finalizeUnlock{value: msg.value}(
msg.sender,
Expand Down Expand Up @@ -404,6 +375,7 @@ contract LockingManager is ILockingManager, PausableUpgradeable, SeqeuncerInfo {
seq.nonce = nonce;

escorow.initializeUnlock{value: msg.value}(_seqId, _l2Gas, seq);
// clear reward at last
seq.reward = 0;
}
}
59 changes: 59 additions & 0 deletions contracts/SeqeuncerInfo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ contract SeqeuncerInfo is OwnableUpgradeable, ISeqeuncerInfo {
mapping(uint256 seqId => Sequencer _seq) public sequencers;

// sequencer owner address => sequencerId
// Note: sequencerId starts from 1
// seqeuncer does not exist if the seqId is 0
mapping(address owner => uint256 seqId) public seqOwners;

// sequencer signer address => sequencerId
// the signer can't be reused afterward if the sequencer exits or updates its pubkey
// It means that the signer is invalid if the seqId is type(uint256).max
mapping(address signer => uint256 seqId) public seqSigners;

// sequencer status => count
Expand Down Expand Up @@ -127,6 +131,61 @@ contract SeqeuncerInfo is OwnableUpgradeable, ISeqeuncerInfo {
return _seqId;
}

/**
* @dev _updateSigner Allow sqeuencer to update new signers to replace old signer addresses,and NFT holder will be transfer driectly
* @param _seqId unique integer to identify a sequencer
* @param _batchId current batch id
* @param _signerPubkey the new signer pubkey address
*/
function _updateSigner(
uint256 _seqId,
uint256 _batchId,
bytes memory _signerPubkey
) internal {
Sequencer storage seq = sequencers[_seqId];
if (seq.status != Status.Active) {
revert SeqNotActive();
}

// only update by the signer
address signer = seq.signer;
if (signer != msg.sender) {
revert NotSeqSigner();
}

address newSigner = _getAddrByPubkey(_signerPubkey);
// the new signer should not be a signer before
if (seqSigners[newSigner] != 0) {
revert OwnedSigner();
}
seq.signer = newSigner;
seqSigners[newSigner] = _seqId;

// invalid it
_invalidSignerAddress(signer);

// set signer updating batch id
seq.updatingBatch = _batchId;

uint256 nonce = seq.nonce + 1;
seq.nonce = nonce;

emit SignerChange(_seqId, signer, newSigner, nonce, _signerPubkey);
}

function _getAddrByPubkey(
bytes memory _signerPubkey
) internal pure returns (address) {
require(_signerPubkey.length == 64, "invalid pubkey");
address newSigner = address(uint160(uint256(keccak256(_signerPubkey))));
require(newSigner != address(0), "empty address");
return newSigner;
}

function _invalidSignerAddress(address _signer) internal {
seqSigners[_signer] = type(uint256).max;
}

/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.20;

import {ISeqeuncerInfo} from "./ISeqeuncerInfo.sol";

interface ILockingEscrow {
interface ILockingInfo {
/**
* @dev Emitted when min lock amount update in 'UpdateMinAmounts'
* @param _newMinLock new min lock.
Expand Down Expand Up @@ -89,11 +89,11 @@ interface ILockingEscrow {
event UnlockInit(
address indexed user,
uint256 indexed sequencerId,
uint256 amount,
uint256 nonce,
uint256 deactivationBatch,
uint256 deactivationTime,
uint256 unlockClaimTime,
uint256 indexed amount
uint256 unlockClaimTime
);

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.20;

interface ILockingManager {
interface ILockingPool {
/**
* @dev Emitted when WITHDRAWAL_DELAY is updated.
* @param _cur current withdraw delay time
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DeployFunction } from "hardhat-deploy/types";
import { LockingEscrowContractName } from "../utils/constant";
import { LockingInfoContractName } from "../utils/constant";

const func: DeployFunction = async function (hre) {
if (!hre.network.tags["l1"]) {
Expand Down Expand Up @@ -35,7 +35,7 @@ const func: DeployFunction = async function (hre) {
l2Chainid,
);

await hre.deployments.deploy(LockingEscrowContractName, {
await hre.deployments.deploy(LockingInfoContractName, {
from: deployer,
proxy: {
proxyContract: "OpenZeppelinTransparentProxy",
Expand All @@ -51,6 +51,6 @@ const func: DeployFunction = async function (hre) {
});
};

func.tags = [LockingEscrowContractName, "l1"];
func.tags = [LockingInfoContractName, "l1"];

export default func;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DeployFunction } from "hardhat-deploy/types";
import {
LockingEscrowContractName,
LockingManagerContractName,
LockingInfoContractName,
LockingPoolContractName,
} from "../utils/constant";

const func: DeployFunction = async function (hre) {
Expand All @@ -11,18 +11,18 @@ const func: DeployFunction = async function (hre) {

const { deployer } = await hre.getNamedAccounts();

const { address: LockingEscrowAddress } = await hre.deployments.get(
LockingEscrowContractName,
const { address: LockingInfoAddress } = await hre.deployments.get(
LockingInfoContractName,
);

await hre.deployments.deploy(LockingManagerContractName, {
await hre.deployments.deploy(LockingPoolContractName, {
from: deployer,
proxy: {
proxyContract: "OpenZeppelinTransparentProxy",
execute: {
init: {
methodName: "initialize",
args: [LockingEscrowAddress],
args: [LockingInfoAddress],
},
},
},
Expand All @@ -31,6 +31,6 @@ const func: DeployFunction = async function (hre) {
});
};

func.tags = [LockingManagerContractName, "l1"];
func.tags = [LockingPoolContractName, "l1"];

export default func;
22 changes: 11 additions & 11 deletions ts-src/deploy/04_L1Config.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { DeployFunction } from "hardhat-deploy/types";
import {
LockingEscrowContractName,
LockingManagerContractName,
LockingInfoContractName,
LockingPoolContractName,
} from "../utils/constant";

const func: DeployFunction = async function (hre) {
if (!hre.network.tags["l1"]) {
throw new Error(`current network ${hre.network.name} is not an L1`);
}

const { address: LockingEscrowAddress } = await hre.deployments.get(
LockingEscrowContractName,
const { address: LockingInfoAddress } = await hre.deployments.get(
LockingInfoContractName,
);

const { address: LockingManagerAddress } = await hre.deployments.get(
LockingManagerContractName,
const { address: LockingPoolAddress } = await hre.deployments.get(
LockingPoolContractName,
);

const lockingEscrow = await hre.ethers.getContractAt(
"LockingEscrow",
LockingEscrowAddress,
const lockingInfo = await hre.ethers.getContractAt(
LockingInfoContractName,
LockingInfoAddress,
);

if ((await lockingEscrow.manager()) == hre.ethers.ZeroAddress) {
if ((await lockingInfo.manager()) == hre.ethers.ZeroAddress) {
console.log("updating manager address for LockingEscrow");
const tx = await lockingEscrow.initManager(LockingManagerAddress);
const tx = await lockingInfo.initManager(LockingPoolAddress);
console.log(`done block=${tx.blockNumber} tx=${tx.hash}`);
}
};
Expand Down
Empty file added ts-src/tasks/dev.ts
Empty file.
Loading

0 comments on commit 7adc031

Please sign in to comment.