diff --git a/src/IScribeFactory.sol b/src/IScribeFactory.sol index 97acaf3..2e1a2ba 100644 --- a/src/IScribeFactory.sol +++ b/src/IScribeFactory.sol @@ -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); } diff --git a/src/ScribeFactory.sol b/src/ScribeFactory.sol index 50071e9..3f80aa9 100644 --- a/src/ScribeFactory.sol +++ b/src/ScribeFactory.sol @@ -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 @@ -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. @@ -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. diff --git a/test/IScribeFactoryTest.sol b/test/IScribeFactoryTest.sol index 78f17aa..efd1e8c 100644 --- a/test/IScribeFactoryTest.sol +++ b/test/IScribeFactoryTest.sol @@ -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 -- @@ -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 -- @@ -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. @@ -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 --