UNPKG

@usecannon/router

Version:

Fork of Synthetix Router Proxy Architecture Manager, including only contract generation logic.

2 lines 3.51 kB
export declare const routerTemplate = "//SPDX-License-Identifier: Unlicense\npragma solidity ^0.8.0;\n\n// --------------------------------------------------------------------------------\n// --------------------------------------------------------------------------------\n// GENERATED CODE - do not edit manually!!\n// This code was generated by the Synthetix router project and deployed with Cannon.\n// Learn more: https://usecannon.com/learn/guides/router\n// --------------------------------------------------------------------------------\n// --------------------------------------------------------------------------------\n\ncontract {{{moduleName}}} {\n error UnknownSelector(bytes4 sel);\n\n{{#diamondCompat}}\n address immutable private _ROUTER_ADDRESS;\n\n constructor() {\n _ROUTER_ADDRESS = address(this);\n{{{diamondConstructor}}}\n }\n\n{{/diamondCompat}}\n {{{modules}}}\n{{#receive}}{{{receive}}}{{/receive}}\n{{^receive}}{{/receive}}\n fallback({{#diamondCompat}}bytes calldata cd{{/diamondCompat}}) external payable{{#diamondCompat}} returns (bytes memory){{/diamondCompat}} {\n // Lookup table: Function selector => implementation contract\n bytes4 sig4 = msg.sig;\n address implementation;\n\n assembly {\n let sig32 := shr(224, sig4)\n\n function findImplementation(sig) -> result {\n {{{selectors}}}\n }\n\n implementation := findImplementation(sig32)\n }\n\n if (implementation == address(0)) {\n{{#diamondCompat}}\n // It's possible this contract is being called through yet another proxy. Call the router in order to make sure we have right data.\n if (address(this) != _ROUTER_ADDRESS) {\n (bool success, bytes memory result) = _ROUTER_ADDRESS.call(cd);\n if (success) {\n return result;\n } else {\n revert UnknownSelector(sig4);\n }\n } else {\n // Check for diamond compat call\n if (sig4 == 0x7a0ed627) {\n return abi.encode(_facets());\n }\n if (sig4 == 0xadfca15e) {\n (address facet) = abi.decode(cd[4:], (address));\n return abi.encode(_facetFunctionSelectors(facet));\n }\n if (sig4 == 0x52ef6b2c) {\n return abi.encode(_facetAddresses());\n }\n if (sig4 == 0xcdffacc6) {\n (bytes4 sig) = abi.decode(cd[4:], (bytes4));\n return abi.encode(_facetAddress(sig));\n }\n if (sig4 == 0x8cce96cb) {\n return abi.encode(_emitDiamondCutEvent());\n }\n }\n{{/diamondCompat}}\n revert UnknownSelector(sig4);\n }\n\n // Delegatecall to the implementation contract\n assembly {\n calldatacopy(0, 0, calldatasize())\n\n let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)\n returndatacopy(0, 0, returndatasize())\n\n switch result\n case 0 {\n revert(0, returndatasize())\n }\n default {\n return(0, returndatasize())\n }\n }\n }\n{{#diamondCompat}}\n{{{diamondCompat}}}\n{{/diamondCompat}}\n}\n"; //# sourceMappingURL=router.d.ts.map