Skip to content

Commit ae4c092

Browse files
karim-enkiseln
andauthored
fix: finalise legacy transfers (#297)
* fix: finalise legacy transfers * fix test * Fix formating * pauseAll method * Rename role * Rename role --------- Co-authored-by: kiseln <3428059+kiseln@users.noreply.github.com>
1 parent 4edd747 commit ae4c092

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

evm/src/eNear/contracts/ENearProxy.sol

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,35 @@ pragma solidity 0.8.24;
44
import "../../common/Borsh.sol";
55
import {AccessControlUpgradeable} from '@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol';
66
import {UUPSUpgradeable} from '@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol';
7-
import {IENear} from './IENear.sol';
7+
import {IENear, INearProver} from './IENear.sol';
88
import {ICustomMinter} from '../../common/ICustomMinter.sol';
9+
import "../../omni-bridge/contracts/SelectivePausableUpgradable.sol";
910

10-
contract ENearProxy is UUPSUpgradeable, AccessControlUpgradeable, ICustomMinter {
11+
contract ENearProxy is UUPSUpgradeable, AccessControlUpgradeable, ICustomMinter, SelectivePausableUpgradable {
1112
IENear public eNear;
1213

1314
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
15+
bytes32 public constant PAUSABLE_ADMIN_ROLE = keccak256("PAUSABLE_ADMIN_ROLE");
1416
bytes public nearConnector;
1517
uint256 public currentReceiptId;
18+
INearProver public prover;
19+
20+
uint constant PAUSED_LEGACY_FIN_TRANSFER = 1 << 0;
1621

1722
/// @custom:oz-upgrades-unsafe-allow constructor
1823
constructor() {
1924
_disableInitializers();
2025
}
2126

22-
function initialize(address _eNear, bytes memory _nearConnector, uint256 _currentReceiptId, address _adminAddress) public initializer {
27+
function initialize(address _eNear, address _prover, bytes memory _nearConnector, uint256 _currentReceiptId, address _adminAddress) public initializer {
2328
__UUPSUpgradeable_init();
2429
__AccessControl_init();
2530
eNear = IENear(_eNear);
2631
nearConnector = _nearConnector;
2732
currentReceiptId = _currentReceiptId;
33+
prover = INearProver(_prover);
2834
_grantRole(DEFAULT_ADMIN_ROLE, _adminAddress);
35+
_grantRole(PAUSABLE_ADMIN_ROLE, _msgSender());
2936
}
3037

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

63+
function finaliseNearToEthTransfer(
64+
bytes memory proofData,
65+
uint64 proofBlockHeight
66+
) external whenNotPaused(PAUSED_LEGACY_FIN_TRANSFER) {
67+
require(
68+
prover.proveOutcome(proofData, proofBlockHeight),
69+
"Proof should be valid"
70+
);
71+
72+
eNear.finaliseNearToEthTransfer(proofData, proofBlockHeight);
73+
}
74+
75+
function pauseAll() external onlyRole(PAUSABLE_ADMIN_ROLE) {
76+
_pause(PAUSED_LEGACY_FIN_TRANSFER);
77+
}
78+
79+
function pause(uint flags) external onlyRole(DEFAULT_ADMIN_ROLE) {
80+
_pause(flags);
81+
}
82+
5683
function _authorizeUpgrade(
5784
address newImplementation
5885
) internal override onlyRole(DEFAULT_ADMIN_ROLE) {}

evm/src/eNear/contracts/FakeProver.sol

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// SPDX-License-Identifier: GPL-3.0-or-later
22
pragma solidity 0.8.24;
3-
4-
interface INearProver {
5-
function proveOutcome(bytes calldata proofData, uint64 blockHeight) external view returns (bool);
6-
}
3+
import {INearProver} from './IENear.sol';
74

85
contract FakeProver is INearProver {
96
function proveOutcome(bytes calldata, uint64) external pure returns (bool) {

evm/src/eNear/contracts/IENear.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ interface IENear {
1414
function admin() external view returns (address);
1515
function adminPause(uint256 flags) external;
1616
}
17+
18+
interface INearProver {
19+
function proveOutcome(bytes calldata proofData, uint64 blockHeight) external view returns (bool);
20+
}

evm/src/eNear/scripts.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { HardhatRuntimeEnvironment } from "hardhat/types"
33

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

@@ -12,7 +13,7 @@ task("deploy-e-near-proxy", "Deploys the ENearProxy contract")
1213
const eNearProxyContract = await ethers.getContractFactory("ENearProxy")
1314
const eNearProxy = await upgrades.deployProxy(
1415
eNearProxyContract,
15-
[taskArgs.enear, nearConnector, 0, taskArgs.admin],
16+
[taskArgs.enear, taskArgs.prover, nearConnector, 0, taskArgs.admin],
1617
{
1718
initializer: "initialize",
1819
timeout: 0,

evm/tests/eNearProxy.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ describe("eNearProxy contract", () => {
5454
eNearProxyFactory,
5555
[
5656
await eNear.getAddress(),
57+
await nearProver.getAddress(),
5758
Buffer.from("eNearBridge", "utf-8"),
5859
0,
5960
await deployer.getAddress(),

0 commit comments

Comments
 (0)