# SymmioPartyB

The `SymmioPartyB` contract acts as a management contract for solvers . This contract allows for controlled interaction with the Symmio platform and external addresses for managing roles and permissions. It supports multicast calls to whitelisted external contracts, and implements EIP-1271 signature verification.

***

### Initialization

```solidity
function initialize(address admin, address symmioAddress_) public initializer;
```

Sets up the upgradeable contract. Grants `DEFAULT_ADMIN_ROLE`, `SETTER_ROLE`, and `MANAGER_ROLE` to `admin`. Sets the Symmio diamond address.

The constructor is empty and calls `_disableInitializers()` to prevent direct initialization of the implementation contract.

***

### Roles

| Role                 | Purpose                                                                                      |
| -------------------- | -------------------------------------------------------------------------------------------- |
| `DEFAULT_ADMIN_ROLE` | Set Symmio address, configure restricted selectors                                           |
| `SETTER_ROLE`        | Set the authorized signer                                                                    |
| `MANAGER_ROLE`       | Call restricted selectors, manage multicast whitelist, withdraw tokens                       |
| `TRUSTED_ROLE`       | Call non-restricted selectors on Symmio, call whitelisted external contracts, approve tokens |
| `PAUSER_ROLE`        | Pause the contract                                                                           |
| `UNPAUSER_ROLE`      | Unpause the contract                                                                         |

***

### Admin Functions

#### setSymmioAddress()

```solidity
function setSymmioAddress(address addr) external onlyRole(DEFAULT_ADMIN_ROLE);
```

Updates the Symmio diamond address.

**Event:** `SetSymmioAddress(oldAddress, newAddress)`

#### setRestrictedSelector()

```solidity
function setRestrictedSelector(bytes4 selector, bool state) external onlyRole(DEFAULT_ADMIN_ROLE);
```

Marks a function selector as restricted. Restricted selectors can only be called by `MANAGER_ROLE` — even `TRUSTED_ROLE` is insufficient.

**Event:** `SetRestrictedSelector(selector, state)`

#### setSigner()

```solidity
function setSigner(address _signer) external onlyRole(SETTER_ROLE);
```

Sets the authorized signer address used for EIP-1271 signature verification.

#### setMulticastWhitelist()

```solidity
function setMulticastWhitelist(address addr, bool state) external onlyRole(MANAGER_ROLE);
```

Adds or removes an address from the multicast whitelist. Cannot whitelist the contract's own address.

**Event:** `SetMulticastWhitelist(addr, state)`

***

## Token Management

### \_approve()

```solidity
function _approve(address token, uint256 amount) external onlyRole(TRUSTED_ROLE) whenNotPaused;
```

Approves the Symmio diamond to spend `amount` of `token` from this contract. Reverts with `TokenNotApproved` on failure.

#### withdrawERC20()

```solidity
function withdrawERC20(address token, uint256 amount) external onlyRole(MANAGER_ROLE);
```

Transfers `amount` of `token` to the caller. Reverts with `TokenNotTransferred` on failure.

***

## Call Execution

### \_call()

```solidity
function _call(bytes[] calldata _callDatas) external whenNotPaused nonReentrant;
```

Executes one or more calls to the Symmio diamond. Each call's function selector is checked against `restrictedSelectors` to determine the required role.

### **Access control per call:**

* Restricted selector → requires `MANAGER_ROLE`
* Non-restricted selector → requires `MANAGER_ROLE`, `TRUSTED_ROLE`, or the call must originate from the Instant Layer (`isCallFromInstantLayer()`)

#### \_multicastCall

```solidity
function _multicastCall(address[] calldata destAddresses, bytes[] calldata _callDatas) external whenNotPaused nonReentrant;
```

Executes calls to multiple different target contracts. Arrays must be the same length. Each target is individually validated:

* **Symmio address** → same selector-based access control as `_call`
* **Other addresses** → must be on the multicast whitelist and caller must have `TRUSTED_ROLE`

Reverts with `DestinationNotWhitelisted` if a non-Symmio target isn't whitelisted.

***

### Internal Execution Logic

`_executeCall` handles all security checks for both `_call` and `_multicastCall`:

1. Reverts if destination is `address(0)` or call data is less than 4 bytes.
2. Extracts the function selector from the call data.
3. Checks permissions based on destination and selector (see access control rules above).
4. Executes the call. On failure, bubbles up the revert data.

***

### Pause Control

```solidity
function pause() external onlyRole(PAUSER_ROLE);
function unpause() external onlyRole(UNPAUSER_ROLE);
```

Pauses/unpauses `_call`, `_multicastCall`, and `_approve`. View functions remain available.

***

### EIP-1271 Signature Verification

```solidity
function isValidSignature(bytes32 hash, bytes calldata signature) external view returns (bytes4);
```

Delegates to the `SignatureVerifier` base contract using the configured `signer` address. Returns `0x1626ba7e` if valid, `0xffffffff` otherwise.
