Skip to content

Commit

Permalink
simply (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
hujw77 authored Mar 13, 2024
1 parent 86a3aea commit c5f0ff0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 37 deletions.
7 changes: 3 additions & 4 deletions src/user/AppBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ pragma solidity ^0.8.17;

// https://eips.ethereum.org/EIPS/eip-5164
abstract contract AppBase {
function ormpSender() public view virtual returns (address);
function ormpRecver() public view virtual returns (address);
function protocol() public view virtual returns (address);

modifier onlyORMPRecver() {
require(ormpRecver() == msg.sender, "!ormp-recver");
modifier onlyORMP() {
require(protocol() == msg.sender, "!ormp-recver");
_;
}

Expand Down
8 changes: 2 additions & 6 deletions src/user/Application.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@ abstract contract Application is AppBase {
_ORMP = ormp;
}

function ormpSender() public view virtual override returns (address) {
return _ORMP;
}

function ormpRecver() public view virtual override returns (address) {
function protocol() public view virtual override returns (address) {
return _ORMP;
}

function _setAppConfig(address oracle, address relayer) internal virtual {
IORMP(_ORMP).setAppConfig(oracle, relayer);
IORMP(protocol()).setAppConfig(oracle, relayer);
}
}
36 changes: 10 additions & 26 deletions src/user/UpgradeableApplication.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,24 @@ import "../interfaces/IORMP.sol";
import "./AppBase.sol";

abstract contract UpgradeableApplication is AppBase {
address private _sender;
address private _recver;
address private _ormp;

event SetSender(address ormp);
event SetRecver(address ormp);
event SetORMP(address ormp);

constructor(address ormp) {
_sender = ormp;
_recver = ormp;
_ormp = ormp;
}

function ormpSender() public view virtual override returns (address) {
return _sender;
function protocol() public view virtual override returns (address) {
return _ormp;
}

function ormpRecver() public view virtual override returns (address) {
return _recver;
function _setORMP(address ormp) internal virtual {
_ormp = ormp;
emit SetORMP(ormp);
}

function _setSender(address ormp) internal virtual {
_sender = ormp;
emit SetSender(ormp);
}

function _setRecver(address ormp) internal virtual {
_recver = ormp;
emit SetRecver(ormp);
}

function _setSenderConfig(address oracle, address relayer) internal virtual {
IORMP(ormpSender()).setAppConfig(oracle, relayer);
}

function _setRecverConfig(address oracle, address relayer) internal virtual {
IORMP(ormpRecver()).setAppConfig(oracle, relayer);
function _setAppConfig(address oracle, address relayer) internal virtual {
IORMP(protocol()).setAppConfig(oracle, relayer);
}
}
2 changes: 1 addition & 1 deletion test/user/Application.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ contract UserApplication is Application {
address xmsgSender = _xmsgSender();
require(msgHash == bytes32(uint256(1)));
require(fromChainid == 1);
require(xmsgSender == ormpRecver());
require(xmsgSender == protocol());
}
}

0 comments on commit c5f0ff0

Please sign in to comment.