Skip to content
Open
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
12 changes: 12 additions & 0 deletions src/IScribeFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,16 @@ interface IScribeFactory {
function plantRouter(ScribeRouterConfig calldata cfg)
external
returns (address);

/// @notice Returns whether `addr` is a Scribe instance deployed by this
/// factory.
/// @param addr The address to query.
/// @return True if `addr` was deployed as a Scribe by this factory.
function isScribe(address addr) external view returns (bool);

/// @notice Returns whether `addr` is a ScribeRouter instance deployed by
/// this factory.
/// @param addr The address to query.
/// @return True if `addr` was deployed as a ScribeRouter by this factory.
function isRouter(address addr) external view returns (bool);
}
8 changes: 8 additions & 0 deletions src/ScribeFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ import {LibSecp256k1} from "./libs/LibSecp256k1.sol";
* @custom:security-contact security@chroniclelabs.org
*/
contract ScribeFactory is IScribeFactory, Auth, Toll {
/// @inheritdoc IScribeFactory
mapping(address => bool) public isScribe;

/// @inheritdoc IScribeFactory
mapping(address => bool) public isRouter;

constructor(address initialAuthed) payable Auth(initialAuthed) {}

/// @inheritdoc IScribeFactory
Expand Down Expand Up @@ -71,6 +77,7 @@ contract ScribeFactory is IScribeFactory, Auth, Toll {
function _plantScribe(ScribeConfig calldata cfg) internal returns (Scribe) {
// Deploy scribe.
Scribe scribe = new Scribe(address(this), cfg.wat);
isScribe[address(scribe)] = true;
emit ScribeDeployed(msg.sender, address(scribe), cfg.name);

// Lift validators and set bar.
Expand All @@ -97,6 +104,7 @@ contract ScribeFactory is IScribeFactory, Auth, Toll {
{
// Deploy router.
ScribeRouter router = new ScribeRouter(address(this), cfg.name);
isRouter[address(router)] = true;
emit ScribeRouterDeployed(msg.sender, address(router), cfg.name);

// Rely authed and kiss tolled.
Expand Down
16 changes: 16 additions & 0 deletions test/IScribeFactoryTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ abstract contract IScribeFactoryTest is Test {

// Factory denied.
assertFalse(IAuth(scribe).authed(address(factory)));

// Tracked as scribe, not as router.
assertTrue(factory.isScribe(scribe));
assertFalse(factory.isRouter(scribe));
}

// -- Test: plantRouter --
Expand Down Expand Up @@ -192,6 +196,10 @@ abstract contract IScribeFactoryTest is Test {

// Scribe not set.
assertEq(IScribeRouter(router).scribe(), address(0));

// Tracked as router, not as scribe.
assertTrue(factory.isRouter(router));
assertFalse(factory.isScribe(router));
}

// -- Test: plantScribeWithRouter --
Expand Down Expand Up @@ -236,6 +244,10 @@ abstract contract IScribeFactoryTest is Test {
// Factory denied.
assertFalse(IAuth(scribe).authed(address(factory)));

// Tracked as scribe, not as router.
assertTrue(factory.isScribe(scribe));
assertFalse(factory.isRouter(scribe));

// -- ScribeRouter Checks

// Name set.
Expand All @@ -254,6 +266,10 @@ abstract contract IScribeFactoryTest is Test {

// Factory denied.
assertFalse(IAuth(router).authed(address(factory)));

// Tracked as router, not as scribe.
assertTrue(factory.isRouter(router));
assertFalse(factory.isScribe(router));
}

// -- Test: Toll Protection --
Expand Down
Loading