Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
33 changes: 30 additions & 3 deletions evm/src/eNear/contracts/ENearProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,35 @@ pragma solidity 0.8.24;
import "../../common/Borsh.sol";
import {AccessControlUpgradeable} from '@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol';
import {UUPSUpgradeable} from '@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol';
import {IENear} from './IENear.sol';
import {IENear, INearProver} from './IENear.sol';
import {ICustomMinter} from '../../common/ICustomMinter.sol';
import "../../omni-bridge/contracts/SelectivePausableUpgradable.sol";

contract ENearProxy is UUPSUpgradeable, AccessControlUpgradeable, ICustomMinter {
contract ENearProxy is UUPSUpgradeable, AccessControlUpgradeable, ICustomMinter, SelectivePausableUpgradable {
IENear public eNear;

bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant PAUSE_ROLE = keccak256("PAUSE_ROLE");
bytes public nearConnector;
uint256 public currentReceiptId;
INearProver public prover;

uint constant PAUSED_LEGACY_FIN_TRANSFER = 1 << 0;

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

function initialize(address _eNear, bytes memory _nearConnector, uint256 _currentReceiptId, address _adminAddress) public initializer {
function initialize(address _eNear, address _prover, bytes memory _nearConnector, uint256 _currentReceiptId, address _adminAddress) public initializer {
__UUPSUpgradeable_init();
__AccessControl_init();
eNear = IENear(_eNear);
nearConnector = _nearConnector;
currentReceiptId = _currentReceiptId;
prover = INearProver(_prover);
_grantRole(DEFAULT_ADMIN_ROLE, _adminAddress);
_grantRole(PAUSE_ROLE, _msgSender());
}

function mint(address token, address to, uint128 amount) public onlyRole(MINTER_ROLE) {
Expand Down Expand Up @@ -53,6 +60,26 @@ contract ENearProxy is UUPSUpgradeable, AccessControlUpgradeable, ICustomMinter
eNear.transferToNear(amount, string(''));
}

function finaliseNearToEthTransfer(
bytes memory proofData,
uint64 proofBlockHeight
) external whenNotPaused(PAUSED_LEGACY_FIN_TRANSFER) {
require(
prover.proveOutcome(proofData, proofBlockHeight),
"Proof should be valid"
);

eNear.finaliseNearToEthTransfer(proofData, proofBlockHeight);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to add a separate method to this contract? Why can't we finalize transactions directly in eNear?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will replace eNear prover to the fake one to allow minting through the proxy

}

function pauseAll() external onlyRole(PAUSE_ROLE) {
_pause(PAUSED_LEGACY_FIN_TRANSFER);
}

function pause(uint flags) external onlyRole(DEFAULT_ADMIN_ROLE) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add pauseAll with pause manager role

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

_pause(flags);
}

function _authorizeUpgrade(
address newImplementation
) internal override onlyRole(DEFAULT_ADMIN_ROLE) {}
Expand Down
5 changes: 1 addition & 4 deletions evm/src/eNear/contracts/FakeProver.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.24;

interface INearProver {
function proveOutcome(bytes calldata proofData, uint64 blockHeight) external view returns (bool);
}
import {INearProver} from './IENear.sol';

contract FakeProver is INearProver {
function proveOutcome(bytes calldata, uint64) external pure returns (bool) {
Expand Down
4 changes: 4 additions & 0 deletions evm/src/eNear/contracts/IENear.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ interface IENear {
function admin() external view returns (address);
function adminPause(uint256 flags) external;
}

interface INearProver {
function proveOutcome(bytes calldata proofData, uint64 blockHeight) external view returns (bool);
}
3 changes: 2 additions & 1 deletion evm/src/eNear/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { HardhatRuntimeEnvironment } from "hardhat/types"

task("deploy-e-near-proxy", "Deploys the ENearProxy contract")
.addParam("enear", "Address of eNear contract")
.addParam("prover", "Address of prover contract")
.setAction(async (taskArgs, hre: HardhatRuntimeEnvironment) => {
const { ethers, upgrades } = hre

Expand All @@ -12,7 +13,7 @@ task("deploy-e-near-proxy", "Deploys the ENearProxy contract")
const eNearProxyContract = await ethers.getContractFactory("ENearProxy")
const eNearProxy = await upgrades.deployProxy(
eNearProxyContract,
[taskArgs.enear, nearConnector, 0, taskArgs.admin],
[taskArgs.enear, taskArgs.prover, nearConnector, 0, taskArgs.admin],
{
initializer: "initialize",
timeout: 0,
Expand Down
1 change: 1 addition & 0 deletions evm/tests/eNearProxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe("eNearProxy contract", () => {
eNearProxyFactory,
[
await eNear.getAddress(),
await nearProver.getAddress(),
Buffer.from("eNearBridge", "utf-8"),
0,
await deployer.getAddress(),
Expand Down
Loading