Skip to content
Verified contractExactMIT

SynergyBridge

Address0x66b145ebf6a409f63fdb39d4c4463d4363cfedfe
Balance

0 ETH

 

Transactions

122

 

Compiler

solc 0.8.20

 

Same code

1 more contract

 

Details

Compiler
solc 0.8.20+commit.a1b79de6
Language
solidity
Optimization
Yes, 1 runs
EVM version
shanghai
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,485,139
Creation transaction
0xce6046404d…442e7cca83

contracts/contracts/bridge/SynergyBridge.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

error E_BAL();
error E_CALL();
error E_REENTRANT();
error E_SAME();
error E_ZERO();

interface IERC20BridgeMinimal {
    function balanceOf(address account) external view returns (uint256);
    function transfer(address to, uint256 amount) external returns (bool);
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
}

interface ISynergyBridgeToken {
    function bridgeMint(address to, uint256 amount) external;
    function bridgeBurnFrom(address from, uint256 amount) external;
    function totalSupply() external view returns (uint256);
}

library BridgeSafeToken {
    function safeTransfer(address token, address to, uint256 amount) internal {
        (bool ok, bytes memory ret) = token.call(abi.encodeCall(IERC20BridgeMinimal.transfer, (to, amount)));
        if (!(ok && (ret.length == 0 || abi.decode(ret, (bool))))) revert E_CALL();
    }

    function safeTransferFrom(address token, address from, address to, uint256 amount) internal {
        (bool ok, bytes memory ret) =
            token.call(abi.encodeCall(IERC20BridgeMinimal.transferFrom, (from, to, amount)));
        if (!(ok && (ret.length == 0 || abi.decode(ret, (bool))))) revert E_CALL();
    }
}

contract BridgeReentrancyGuard {
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;
    uint256 private _status = _NOT_ENTERED;

    modifier nonReentrant() {
        if (_status == _ENTERED) revert E_REENTRANT();
        _status = _ENTERED;
        _;
        _status = _NOT_ENTERED;
    }
}

/// @notice 1:1 wrapper between Omnibridge wSYN and mechanics-bearing native Ethereum SYN.
/// @dev Pulse SYN is locked in Omnibridge, Omnibridge mints wSYN on Ethereum, and this
/// bridge holds wSYN collateral while minting/burning native ETH SYN through the token's
/// one-time configured bridge hooks.
contract SynergyBridge is BridgeReentrancyGuard {
    address public immutable SYN;
    address public immutable WSYN;

    event Unwrap(address indexed user, uint256 amount);
    event Wrap(address indexed user, uint256 amount);

    constructor(address syn_, address wsyn_) {
        if (syn_ == address(0) || wsyn_ == address(0)) revert E_ZERO();
        if (syn_ == wsyn_) revert E_SAME();
        SYN = syn_;
        WSYN = wsyn_;
    }

    /// @notice Converts Omnibridge wSYN into native ETH SYN 1:1.
    /// @dev Caller must approve this bridge to spend wSYN first.
    function unwrap(uint256 amount) external nonReentrant {
        if (amount == 0) revert E_ZERO();
        uint256 beforeBal = IERC20BridgeMinimal(WSYN).balanceOf(address(this));
        BridgeSafeToken.safeTransferFrom(WSYN, msg.sender, address(this), amount);
        uint256 received = IERC20BridgeMinimal(WSYN).balanceOf(address(this)) - beforeBal;
        if (received != amount) revert E_BAL();
        ISynergyBridgeToken(SYN).bridgeMint(msg.sender, amount);
        emit Unwrap(msg.sender, amount);
    }

    /// @notice Converts native ETH SYN back into Omnibridge wSYN 1:1.
    /// @dev Caller must approve this bridge to burn native SYN first, because SYN.bridgeBurnFrom
    /// checks allowance when the bridge burns a user's balance.
    function wrap(uint256 amount) external nonReentrant {
        if (amount == 0) revert E_ZERO();
        if (IERC20BridgeMinimal(WSYN).balanceOf(address(this)) < amount) revert E_BAL();
        ISynergyBridgeToken(SYN).bridgeBurnFrom(msg.sender, amount);
        BridgeSafeToken.safeTransfer(WSYN, msg.sender, amount);
        emit Wrap(msg.sender, amount);
    }

    function availableWsyn() external view returns (uint256) {
        return IERC20BridgeMinimal(WSYN).balanceOf(address(this));
    }

    function nativeSupply() external view returns (uint256) {
        return ISynergyBridgeToken(SYN).totalSupply();
    }

    function collateralInvariantHolds() external view returns (bool) {
        return IERC20BridgeMinimal(WSYN).balanceOf(address(this)) == ISynergyBridgeToken(SYN).totalSupply();
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 1,
    "enabled": true
  },
  "evmVersion": "shanghai",
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.