|
| 1 | +// SPDX-License-Identifier: UNLICENSED |
| 2 | +pragma solidity ^0.8.13; |
| 3 | + |
| 4 | +import {RollupOrders} from "zenith/src/orders/RollupOrders.sol"; |
| 5 | +import {RollupPassage} from "zenith/src/passage/RollupPassage.sol"; |
| 6 | +import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; |
| 7 | + |
| 8 | +import {PecorinoConstants} from "./chains/Pecorino.sol"; |
| 9 | + |
| 10 | +contract SignetStd { |
| 11 | + /// @notice The native asset address, used as a sentinel for native USD on |
| 12 | + /// the rollup, or native ETH on the host. |
| 13 | + address constant NATIVE_ASSET = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; |
| 14 | + |
| 15 | + /// @notice The chain ID of the host network. |
| 16 | + uint32 internal immutable HOST_CHAIN_ID; |
| 17 | + |
| 18 | + /// @notice The Rollup Passage contract. |
| 19 | + RollupPassage internal immutable PASSAGE; |
| 20 | + /// @notice The Rollup Orders contract. |
| 21 | + RollupOrders internal immutable ORDERS; |
| 22 | + |
| 23 | + /// @notice The WETH token address. |
| 24 | + IERC20 internal immutable WETH; |
| 25 | + /// @notice The WBTC token address. |
| 26 | + IERC20 internal immutable WBTC; |
| 27 | + /// @notice The WUSD token address. |
| 28 | + IERC20 internal immutable WUSD; |
| 29 | + |
| 30 | + /// @notice The USDC token address on the host network. |
| 31 | + address internal immutable HOST_USDC; |
| 32 | + /// @notice The USDT token address on the host network. |
| 33 | + address internal immutable HOST_USDT; |
| 34 | + /// @notice The WBTC token address on the host network. |
| 35 | + address internal immutable HOST_WBTC; |
| 36 | + /// @notice The WETH token address on the host network. |
| 37 | + address internal immutable HOST_WETH; |
| 38 | + |
| 39 | + constructor() { |
| 40 | + // Auto-configure based on the chain ID. |
| 41 | + if (block.chainid == PecorinoConstants.ROLLUP_CHAIN_ID) { |
| 42 | + HOST_CHAIN_ID = PecorinoConstants.HOST_CHAIN_ID; |
| 43 | + |
| 44 | + PASSAGE = PecorinoConstants.PECORINO_ROLLUP_PASSAGE; |
| 45 | + ORDERS = PecorinoConstants.PECORINO_ROLLUP_ORDERS; |
| 46 | + |
| 47 | + WETH = PecorinoConstants.WETH; |
| 48 | + WBTC = PecorinoConstants.WBTC; |
| 49 | + WUSD = PecorinoConstants.WUSD; |
| 50 | + |
| 51 | + HOST_USDC = PecorinoConstants.HOST_USDC; |
| 52 | + HOST_USDT = PecorinoConstants.HOST_USDT; |
| 53 | + HOST_WBTC = PecorinoConstants.HOST_WBTC; |
| 54 | + HOST_WETH = PecorinoConstants.HOST_WETH; |
| 55 | + } else { |
| 56 | + revert("Unsupported chain"); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + /// @notice Creates an Input struct for the RollupOrders. |
| 61 | + /// @param token The address of the token. |
| 62 | + /// @param amount The amount of the token. |
| 63 | + /// @return input The created Input struct. |
| 64 | + function makeInput(address token, uint256 amount) internal pure returns (RollupOrders.Input memory input) { |
| 65 | + input.token = token; |
| 66 | + input.amount = amount; |
| 67 | + } |
| 68 | + |
| 69 | + /// @notice Creates an Output struct for the RollupOrders. |
| 70 | + /// @param token The address of the token. |
| 71 | + /// @param amount The amount of the token. |
| 72 | + /// @param recipient The address to receive the output tokens. |
| 73 | + /// @param chainId The chain ID for the output. |
| 74 | + /// @return output The created Output struct. |
| 75 | + function makeOutput(address token, uint256 amount, address recipient, uint32 chainId) |
| 76 | + private |
| 77 | + pure |
| 78 | + returns (RollupOrders.Output memory output) |
| 79 | + { |
| 80 | + output.token = token; |
| 81 | + output.amount = amount; |
| 82 | + output.recipient = recipient; |
| 83 | + output.chainId = chainId; |
| 84 | + } |
| 85 | + |
| 86 | + /// @notice Creates an Output struct for the host network. |
| 87 | + /// @param token The address of the token. |
| 88 | + /// @param amount The amount of the token. |
| 89 | + /// @param recipient The address to receive the output tokens. |
| 90 | + /// @return output The created Output struct for the host network. |
| 91 | + function makeHostOutput(address token, uint256 amount, address recipient) |
| 92 | + internal |
| 93 | + view |
| 94 | + returns (RollupOrders.Output memory output) |
| 95 | + { |
| 96 | + return makeOutput(token, amount, recipient, HOST_CHAIN_ID); |
| 97 | + } |
| 98 | + |
| 99 | + /// @notice Creates an Output struct for the rollup network. |
| 100 | + /// @param token The address of the token. |
| 101 | + /// @param amount The amount of the token. |
| 102 | + /// @param recipient The address to receive the output tokens. |
| 103 | + /// @return output The created Output struct for the rollup network. |
| 104 | + function makeRollupOutput(address token, uint256 amount, address recipient) |
| 105 | + internal |
| 106 | + view |
| 107 | + returns (RollupOrders.Output memory output) |
| 108 | + { |
| 109 | + return makeOutput(token, amount, recipient, uint32(block.chainid)); |
| 110 | + } |
| 111 | + |
| 112 | + /// @notice Creates an Output struct for the host USDC token. |
| 113 | + /// @param amount The amount of USDC to receive. |
| 114 | + /// @param recipient The address to receive the USDC tokens. |
| 115 | + /// @return output The created Output struct for the host USDC token. |
| 116 | + function hostUsdcOutput(uint256 amount, address recipient) |
| 117 | + internal |
| 118 | + view |
| 119 | + returns (RollupOrders.Output memory output) |
| 120 | + { |
| 121 | + return makeHostOutput(HOST_USDC, amount, recipient); |
| 122 | + } |
| 123 | + |
| 124 | + /// @notice Creates an Output struct for the host USDT token. |
| 125 | + /// @param amount The amount of USDT to receive. |
| 126 | + /// @param recipient The address to receive the USDT tokens. |
| 127 | + /// @return output The created Output struct for the host USDT token. |
| 128 | + function hostUsdtOutput(uint256 amount, address recipient) |
| 129 | + internal |
| 130 | + view |
| 131 | + returns (RollupOrders.Output memory output) |
| 132 | + { |
| 133 | + return makeHostOutput(HOST_USDT, amount, recipient); |
| 134 | + } |
| 135 | + |
| 136 | + /// @notice Creates an Output struct for the host WBTC token. |
| 137 | + /// @param amount The amount of WBTC to receive. |
| 138 | + /// @param recipient The address to receive the WBTC tokens. |
| 139 | + /// @return output The created Output struct for the host WBTC token. |
| 140 | + function hostWbtcOutput(uint256 amount, address recipient) |
| 141 | + internal |
| 142 | + view |
| 143 | + returns (RollupOrders.Output memory output) |
| 144 | + { |
| 145 | + return makeHostOutput(HOST_WBTC, amount, recipient); |
| 146 | + } |
| 147 | + |
| 148 | + /// @notice Creates an Output struct for the host WETH token. |
| 149 | + /// @param amount The amount of WETH to receive. |
| 150 | + /// @param recipient The address to receive the WETH tokens. |
| 151 | + /// @return output The created Output struct for the host WETH token. |
| 152 | + function hostWethOutput(uint256 amount, address recipient) |
| 153 | + internal |
| 154 | + view |
| 155 | + returns (RollupOrders.Output memory output) |
| 156 | + { |
| 157 | + return makeHostOutput(HOST_WETH, amount, recipient); |
| 158 | + } |
| 159 | + |
| 160 | + /// @notice Creates an Output struct for the host native asset (ETH). |
| 161 | + /// @param amount The amount of native asset to receive. |
| 162 | + /// @param recipient The address to receive the native asset. |
| 163 | + /// @return output The created Output struct for the host native asset. |
| 164 | + function hostEthOutput(uint256 amount, address recipient) |
| 165 | + internal |
| 166 | + view |
| 167 | + returns (RollupOrders.Output memory output) |
| 168 | + { |
| 169 | + return makeHostOutput(NATIVE_ASSET, amount, recipient); |
| 170 | + } |
| 171 | +} |
0 commit comments