Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simply application #138

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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());
}
}
Loading