Core/Periphery Design Pattern for Immutable Protocols
Last updated
// Core: immutable pool
contract Pool {
uint112 reserve0;
uint112 reserve1;
function swap(uint amount0Out, uint amount1Out) external {
// Invariant: x * y >= k
require(amount0Out == 0 || amount1Out == 0, "Only one side out");
// ...
}
}
// Periphery: router that interacts with core
contract Router {
function swapExactTokensForTokens(...) external {
// Handle approvals, slippage checks, path routing
Pool(pool).swap(...);
}
}