Skip to content
Merged
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
16 changes: 13 additions & 3 deletions script/DeploySignedProposer.s.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.27;

import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {Script} from "forge-std/Script.sol";
import {console} from "forge-std/console.sol";
import {ISignatureTransfer} from "permit2/src/interfaces/ISignatureTransfer.sol";
Expand All @@ -9,7 +10,7 @@ import {SignedProposer} from "../src/optimistic-oracle-v2/implementation/SignedP

/**
* @title Deployment script for SignedProposer
* @notice Deploys SignedProposer with configurable Permit2 and admin addresses
* @notice Deploys a UUPS SignedProposer implementation and atomically initialized ERC1967 proxy
*
* Environment variables:
* - MNEMONIC: Required. The mnemonic phrase for the deployer wallet
Expand All @@ -33,12 +34,21 @@ contract DeploySignedProposer is Script {

vm.startBroadcast(deployerPrivateKey);

signedProposer = new SignedProposer(ISignatureTransfer(permit2Address), admin);
SignedProposer implementation = new SignedProposer();
signedProposer = SignedProposer(
address(
new ERC1967Proxy(
address(implementation),
abi.encodeCall(SignedProposer.initialize, (ISignatureTransfer(permit2Address), admin))
)
)
);

vm.stopBroadcast();

console.log("\n=== Deployment Summary ===");
console.log("SignedProposer:", address(signedProposer));
console.log("SignedProposer proxy:", address(signedProposer));
console.log("SignedProposer implementation:", address(implementation));
console.log("Chain ID:", block.chainid);
console.log("Deployer:", deployer);
console.log("Permit2:", permit2Address);
Expand Down
26 changes: 21 additions & 5 deletions script/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,23 +307,37 @@ The `ManagedOptimisticOracleV2` contract:

## SignedProposer Deployment

The `DeploySignedProposer.s.sol` script deploys `SignedProposer` using the canonical Permit2 deployment by default.
The `DeploySignedProposer.s.sol` script deploys a UUPS `SignedProposer` implementation and an ERC1967 proxy, atomically calling `initialize(permit2, admin)` during proxy construction. It uses the canonical Permit2 deployment by default and logs both addresses. The implementation disables initialization.

### Environment Variables

| Variable | Required | Description |
|----------|----------|-------------|
| `MNEMONIC` | Yes | The mnemonic phrase for the deployer wallet (uses 0 index address) |
| `PERMIT2_ADDRESS` | No | Permit2 address; defaults to `0x000000000022D473030F116dDEE9F6B43aC78BA3` |
| `SIGNED_PROPOSER_ADMIN` | No | Address receiving the default admin role; defaults to the deployer |
| `SIGNED_PROPOSER_ADMIN` | No | Address receiving the default admin role, including upgrade authority; defaults to the deployer |

### Usage

```bash
forge script script/DeploySignedProposer.s.sol --rpc-url "YOUR_RPC_URL" --broadcast
```

The script only deploys the contract. The admin configures delegated proposers and any required whitelist ownership separately.
The script deploys and initializes the proxy. The admin configures delegated proposers and any required whitelist ownership separately. Use the **proxy address** for all relay calls, the Permit2 spender in signatures, whitelist membership, and whitelist ownership.

### Upgradeability

SignedProposer uses the same OpenZeppelin UUPS/ERC1967 mechanism as Managed OO and OOReporter. Its existing `DEFAULT_ADMIN_ROLE` authorizes `upgradeToAndCall(newImplementation, data)` on the proxy; no separate owner, proxy admin contract, or upgrade role is added. Delegated proposers and whitelist admins cannot upgrade unless they also hold the default admin role. Use empty `data` when no migration is needed; do not call `initialize` again.

The Permit2 address is initialized in proxy storage. Roles, retained token balances, whitelist ownership, and the Permit2 spender address survive compatible implementation upgrades. Existing signatures remain usable subject to their original deadlines, nonce usage, and proposal validity. The default admin is trusted to install implementations that can change relay behavior, including how outstanding signatures are handled.

Future upgrades must preserve the storage layout, including the inherited `TryMulticall` batch lock and `permit2`, and retain the UUPS authorization hook. Validate storage compatibility against the deployed build before upgrading. This deployment change does not retrofit upgradeability onto any previously deployed direct SignedProposer instance; that requires a new proxy deployment and updating integrations to its address.

The integrated layout stores the batch lock in the ERC-7201 namespace `uma.storage.TryMulticall` and `permit2` at
slot 0, offset 0. This is the layout for the initial proxy deployment. The earlier UUPS proposal with a sequential batch
lock placed `permit2` at slot 0, offset 1; it is not storage-compatible with this version. Do not upgrade a proxy using
that earlier layout directly to this implementation. Such a deployment requires a separately reviewed migration or a
new proxy. The integration does not include a storage migration.

### Partial-success proposal batches

Expand All @@ -339,7 +353,7 @@ batch reverts and rolls back earlier successes.

Polygon Bor rejects transactions larger than 128 KiB. With the maximum valid OOv2 ancillary data
of 8,139 non-zero bytes, each encoded `propose` child is 8,804 bytes: 14 children produce 124,612
bytes of outer calldata and execute within the 53,902,641 gas limit at pinned block `81,683,818`,
bytes of outer calldata; the proxy-based capacity test uses the 53,902,641 gas limit at pinned block `81,683,818`,
while 15 children produce 133,508 bytes before the signed transaction envelope and are rejected.
Smaller ancillary data permits larger batches, subject to the same transaction-size and gas bounds.

Expand Down Expand Up @@ -373,8 +387,10 @@ reachable functions must retain their own authorization because `multicall` does

### Verification

Verify the implementation with no constructor arguments. Verify the ERC1967 proxy separately using its implementation address and encoded `initialize(permit2, admin)` calldata as constructor arguments.

```bash
forge verify-contract <SIGNED_PROPOSER_ADDRESS> src/optimistic-oracle-v2/implementation/SignedProposer.sol:SignedProposer --chain-id <CHAIN_ID> --constructor-args $(cast abi-encode "constructor(address,address)" <PERMIT2_ADDRESS> <SIGNED_PROPOSER_ADMIN>) --etherscan-api-key <YOUR_ETHERSCAN_API_KEY>
forge verify-contract <SIGNED_PROPOSER_IMPLEMENTATION_ADDRESS> src/optimistic-oracle-v2/implementation/SignedProposer.sol:SignedProposer --chain-id <CHAIN_ID> --etherscan-api-key <YOUR_ETHERSCAN_API_KEY>
```

## ManagedOptimisticOracleV2 Upgrade
Expand Down
41 changes: 34 additions & 7 deletions src/optimistic-oracle-v2/implementation/SignedProposer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ pragma solidity ^0.8.27;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
import {Multicall} from "@openzeppelin/contracts/utils/Multicall.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import {MulticallUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/MulticallUpgradeable.sol";
import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import {OptimisticOracleV2Interface} from "../interfaces/OptimisticOracleV2Interface.sol";
import {SignedProposerOracleInterface} from "../interfaces/SignedProposerOracleInterface.sol";
import {ISignatureTransfer} from "permit2/src/interfaces/ISignatureTransfer.sol";
import {AddressWhitelist} from "../../common/implementation/AddressWhitelist.sol";
import {AddressWhitelistInterface} from "../../common/interfaces/AddressWhitelistInterface.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {TryMulticall} from "../../common/implementation/TryMulticall.sol";

/**
Expand All @@ -32,7 +33,11 @@ import {TryMulticall} from "../../common/implementation/TryMulticall.sol";
* spender and the `proposePriceFor` call target, so executing an unintended oracle can spend up to
* the signer-approved Permit2 amount for that proposal.
*
* Deploy behind an ERC1967Proxy and initialize atomically. The default admin authorizes UUPS
* upgrades; the proxy remains the Permit2 spender and whitelist owner across upgrades.
*
* The contract is permissioned:
* - `DEFAULT_ADMIN_ROLE` — manages roles, payments, whitelist ownership, and upgrades.
* - `DELEGATED_PROPOSER_ROLE` — may call `propose` and `tryMulticall`.
* - `WHITELIST_ADMIN_ROLE` — may directly add/remove entries on whitelists owned by this contract.
*
Expand All @@ -42,7 +47,13 @@ import {TryMulticall} from "../../common/implementation/TryMulticall.sol";
* apply their own. `tryMulticall` instead restricts the caller to delegated proposers, accepts only `propose`, and rejects
* nested partial-success batches. These restrictions do not apply to the atomic `multicall` entry point.
*/
contract SignedProposer is AccessControl, Multicall, ReentrancyGuard, TryMulticall {
contract SignedProposer is
AccessControlUpgradeable,
MulticallUpgradeable,
ReentrancyGuardUpgradeable,
UUPSUpgradeable,
TryMulticall
{
using SafeERC20 for IERC20;

// ─── Structs ──────────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -73,9 +84,9 @@ contract SignedProposer is AccessControl, Multicall, ReentrancyGuard, TryMultica
string public constant WITNESS_TYPE_STRING =
"Proposal witness)Proposal(address oracle,address requester,bytes32 identifier,uint256 timestamp,bytes ancillaryData,int256 proposedPrice,uint256 maxPayment)TokenPermissions(address token,uint256 amount)";

// ─── Immutables ───────────────────────────────────────────────────────────────
// ─── Storage ───────────────────────────────────────────────────────────────

ISignatureTransfer public immutable permit2;
ISignatureTransfer public permit2;

// ─── Events ───────────────────────────────────────────────────────────────────

Expand All @@ -92,18 +103,34 @@ contract SignedProposer is AccessControl, Multicall, ReentrancyGuard, TryMultica

event PaymentWithdrawn(address indexed token, address indexed to, uint256 amount);

error ZeroAddress();
error PaymentExceedsMaxPayment();
error PermitTransferAmountMismatch(uint256 expectedAmount, uint256 receivedAmount);
error PermitTokenMismatch(address requestCurrency, address permitToken);
error CannotRemoveSelfFromWhitelist();
error NewOwnerNotWhitelisted(address newOwner);

// ─── Constructor ──────────────────────────────────────────────────────────────

constructor(ISignatureTransfer _permit2, address admin) {
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

/// @notice Initializes the proxy with its Permit2 contract and role/upgrade administrator.
function initialize(ISignatureTransfer _permit2, address admin) external initializer {
if (address(_permit2) == address(0) || admin == address(0)) revert ZeroAddress();
__AccessControl_init();
__Multicall_init();
__ReentrancyGuard_init();
__UUPSUpgradeable_init();
permit2 = _permit2;
_grantRole(DEFAULT_ADMIN_ROLE, admin);
}

/// @dev Reuses the existing admin role rather than introducing a separate upgrade authority.
function _authorizeUpgrade(address) internal override onlyRole(DEFAULT_ADMIN_ROLE) {}

// ─── Propose ──────────────────────────────────────────────────────────────────

/**
Expand Down
Loading
Loading