Skip to content

Commit

Permalink
implement OnlyOracle contract and integrate it into Errantry and Erra…
Browse files Browse the repository at this point in the history
…ntryClientSmartAccount
  • Loading branch information
Da-Colon committed Dec 28, 2024
1 parent c781554 commit b10c321
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
16 changes: 11 additions & 5 deletions contracts/src/Errantry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {ErrandManager} from "./ErrandManager.sol";
import {Lib} from "./libraries/Lib.sol";
import {ErrantryClientSmartAccount} from "./ErrantryClientSmartAccount.sol";
import {IEntryPoint} from "@account-abstraction/contracts/interfaces/IEntryPoint.sol";
import "./OnlyOracle.sol";

/**
* Definitions:
Expand All @@ -14,18 +15,21 @@ import {IEntryPoint} from "@account-abstraction/contracts/interfaces/IEntryPoint
* - Errand Client: a person who requests errands to be run
*/

contract Errantry is IErrantry {
contract Errantry is IErrantry, OnlyOracle {
IEntryPoint private SA_ENTRY_POINT;
address private TRUSTED_ORACLE;
error ClientAlreadyRegistered();

event ClientRegistered(address indexed client, address smartAccount);

// only the oracle can post new errands

mapping(address => Lib.Client) private clients;

constructor(IEntryPoint _entry_point, address _trusted_oracle) {
constructor(
IEntryPoint _entry_point,
address _trusted_oracle
) OnlyOracle(_trusted_oracle) {
SA_ENTRY_POINT = _entry_point;
TRUSTED_ORACLE = _trusted_oracle;
}

/* >>>>>>>> open access external functions <<<<<<< */
Expand Down Expand Up @@ -62,7 +66,9 @@ contract Errantry is IErrantry {
}

/* >>>>>>>> oracle functions <<<<<<< */
function postNewErrand(Lib.PostNewErrandParams calldata params) public {
function postNewErrand(
Lib.PostNewErrandParams calldata params
) public onlyOracle {
clients[params.client].errandManager.postNewErrand(params);
}

Expand Down
12 changes: 5 additions & 7 deletions contracts/src/ErrantryClientSmartAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
pragma solidity ^0.8.28;
import "@account-abstraction/contracts/samples/SimpleAccount.sol";
import {IErrantryClientSmartAccount} from "./interfaces/IErrantryClientSmartAccount.sol";
import "./OnlyOracle.sol";

contract ErrantryClientSmartAccount is
IErrantryClientSmartAccount,
SimpleAccount
SimpleAccount,
OnlyOracle
{
address private TRUSTED_ORACLE;

constructor(
IEntryPoint _entryPoint,
address _trustedOracle
) SimpleAccount(_entryPoint) {
TRUSTED_ORACLE = _trustedOracle;
}
) SimpleAccount(_entryPoint) OnlyOracle(_trustedOracle) {}

/* >>>>>>>> general external functions <<<<<<< */
function _validateSignature(
Expand All @@ -32,7 +30,7 @@ contract ErrantryClientSmartAccount is
}

/* >>>>>>>> oracle functions <<<<<<< */
function markErrandAsComplete() external {}
function markErrandAsComplete() external onlyOracle {}

/* >>>>>>>> internal functions <<<<<<< */
function _checkErrandFundBalance() internal {}
Expand Down
15 changes: 15 additions & 0 deletions contracts/src/OnlyOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

contract OnlyOracle {
address internal TRUSTED_ORACLE;

constructor(address _trustedOracle) {
TRUSTED_ORACLE = _trustedOracle;
}

modifier onlyOracle() {
require(msg.sender == TRUSTED_ORACLE, "ErrantryUtils: only oracle");
_;
}
}

0 comments on commit b10c321

Please sign in to comment.