Verified contractExactMIT
BebopOndoHook
Address0x7ea8daddcbc7afcbeaa6857a9c82e70bc5b9daf5
- Balance
0 ETH
- Transactions
2
- Compiler
solc 0.8.24
- Same code
Only this contract
Details
- Compiler
- solc 0.8.24+commit.e11b9ed9
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,285,178
- Creation transaction
- 0xbc72ab4bfe…54ac40d4a6
5 files
- src/BebopOndoHook.solmain4.96 KB
- lib/solmate/src/auth/Owned.sol1.47 KB
- lib/solmate/src/tokens/ERC20.sol6.81 KB
- lib/solmate/src/utils/SafeTransferLib.sol5.77 KB
- src/external/IGMTokenManager.sol2.13 KB
src/BebopOndoHook.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {Owned} from "solmate/auth/Owned.sol";
import {ERC20} from "solmate/tokens/ERC20.sol";
import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol";
import {IGMTokenManager} from "./external/IGMTokenManager.sol";
/// @dev The router's view of this maker's swap legs (bebop-rfqa `IBebopHook`).
struct Swap {
uint256 takerAmount;
address takerToken;
uint256 makerAmount;
address makerToken;
}
/**
* Zero-inventory mint/redeem pre-hook for Bebop RFQ
* (docs.bebop.xyz/market-makers/core-concepts/zero-inventory).
*
* A zero-inventory fill settles as a self-swap on the OUTPUT token, so the
* BebopRouter must already hold that output when the PMM leg runs. This hook puts
* it there. Before the swap, the router approves this contract for the taker's input
* (`needs_approval`) and calls `bebopHook`. The hook then:
* 1. pulls the input (`quoteInputAmount`) from the router,
* 2. mints (USDC -> GM) or redeems (GM -> USDC) it through Ondo's GM manager under
* the Ondo-signed attestation carried in `issuerData` — THIS contract is the
* Ondo-whitelisted user, the way `UniswapXOndoExecutor` is,
* 3. sends exactly `quoteOutputAmount` of the output back to the router.
* The proceeds above `quoteOutputAmount` are the maker's margin. They stay here
* until the owner sweeps them.
*
* `data` = abi.encode(uint8 action, address inputToken, address outputToken,
* uint256 quoteInputAmount, uint256 quoteOutputAmount, bytes issuerData),
* `issuerData` = abi.encode(IGMTokenManager.Quote, bytes ondoSignature).
*
* Trust:
* - only the router may call it, and the router passes `makerAddress` from the
* maker-signed hook, so `data` cannot redirect it. Only makers the owner lists
* may use it, so no one else can spend the Ondo whitelisting on this address;
* - the rate bound is checked here. The output must cover `quoteOutputAmount`, or
* the whole swap reverts (`revert_on_fail`). Ondo's attestation fixes its own
* price and expiry;
* - all token calls go through SafeTransferLib.
*/
contract BebopOndoHook is Owned {
using SafeTransferLib for ERC20;
address public immutable router;
IGMTokenManager public immutable gm;
ERC20 public immutable usdc;
mapping(address => bool) public isMaker;
event MakerSet(address indexed maker, bool allowed);
event Filled(address indexed maker, uint8 action, address indexed gmToken, uint256 amountIn, uint256 amountOut, uint256 surplus);
error NotRouter();
error NotMaker();
error BadLeg();
error ShortOutput();
constructor(address _owner, address _router, address _gm, address _usdc) Owned(_owner) {
router = _router;
gm = IGMTokenManager(_gm);
usdc = ERC20(_usdc);
}
function setMaker(address maker, bool allowed) external onlyOwner {
isMaker[maker] = allowed;
emit MakerSet(maker, allowed);
}
/// @notice Withdraw accumulated margin (or anything sent here by mistake).
function sweep(ERC20 token, address to, uint256 amount) external onlyOwner {
token.safeTransfer(to, amount);
}
function bebopHook(address makerAddress, bytes calldata data, Swap[] calldata) external {
if (msg.sender != router) revert NotRouter();
if (!isMaker[makerAddress]) revert NotMaker();
(uint8 action, address inputToken, address outputToken, uint256 amountIn, uint256 amountOut, bytes memory issuer) =
abi.decode(data, (uint8, address, address, uint256, uint256, bytes));
(IGMTokenManager.Quote memory q, bytes memory signature) = abi.decode(issuer, (IGMTokenManager.Quote, bytes));
ERC20(inputToken).safeTransferFrom(router, address(this), amountIn);
uint256 before = ERC20(outputToken).balanceOf(address(this));
if (action == 0) {
// Mint: USDC in, the attested GM out.
if (inputToken != address(usdc) || outputToken != q.asset || q.side != 0) revert BadLeg();
usdc.safeApprove(address(gm), amountIn);
gm.mintWithAttestation(q, signature, address(usdc), amountIn);
} else if (action == 1) {
// Redeem: the attested GM in, USDC out, floored at what we quoted.
if (outputToken != address(usdc) || inputToken != q.asset || q.side != 1 || q.quantity != amountIn) {
revert BadLeg();
}
ERC20(inputToken).safeApprove(address(gm), amountIn);
gm.redeemWithAttestation(q, signature, address(usdc), amountOut);
} else {
revert BadLeg();
}
uint256 got = ERC20(outputToken).balanceOf(address(this)) - before;
if (got < amountOut) revert ShortOutput();
ERC20(outputToken).safeTransfer(router, amountOut);
emit Filled(makerAddress, action, q.asset, amountIn, amountOut, got - amountOut);
}
}
lib/solmate/src/auth/Owned.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
/// @notice Simple single owner authorization mixin.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Owned.sol)
abstract contract Owned {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event OwnershipTransferred(address indexed user, address indexed newOwner);
/*//////////////////////////////////////////////////////////////
OWNERSHIP STORAGE
//////////////////////////////////////////////////////////////*/
address public owner;
modifier onlyOwner() virtual {
require(msg.sender == owner, "UNAUTHORIZED");
_;
}
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(address _owner) {
owner = _owner;
emit OwnershipTransferred(address(0), _owner);
}
/*//////////////////////////////////////////////////////////////
OWNERSHIP LOGIC
//////////////////////////////////////////////////////////////*/
function transferOwnership(address newOwner) public virtual onlyOwner {
owner = newOwner;
emit OwnershipTransferred(msg.sender, newOwner);
}
}
lib/solmate/src/tokens/ERC20.sol
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)
/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
abstract contract ERC20 {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
/*//////////////////////////////////////////////////////////////
METADATA STORAGE
//////////////////////////////////////////////////////////////*/
string public name;
string public symbol;
uint8 public immutable decimals;
/*//////////////////////////////////////////////////////////////
ERC20 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
/*//////////////////////////////////////////////////////////////
EIP-2612 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 internal immutable INITIAL_CHAIN_ID;
bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;
mapping(address => uint256) public nonces;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(
string memory _name,
string memory _symbol,
uint8 _decimals
) {
name = _name;
symbol = _symbol;
decimals = _decimals;
INITIAL_CHAIN_ID = block.chainid;
INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
}
/*//////////////////////////////////////////////////////////////
ERC20 LOGIC
//////////////////////////////////////////////////////////////*/
function approve(address spender, uint256 amount) public virtual returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transfer(address to, uint256 amount) public virtual returns (bool) {
balanceOf[msg.sender] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public virtual returns (bool) {
uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.
if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;
balanceOf[from] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
return true;
}
/*//////////////////////////////////////////////////////////////
EIP-2612 LOGIC
//////////////////////////////////////////////////////////////*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");
// Unchecked because the only math done is incrementing
// the owner's nonce which cannot realistically overflow.
unchecked {
address recoveredAddress = ecrecover(
keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
),
owner,
spender,
value,
nonces[owner]++,
deadline
)
)
)
),
v,
r,
s
);
require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");
allowance[recoveredAddress][spender] = value;
}
emit Approval(owner, spender, value);
}
function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
}
function computeDomainSeparator() internal view virtual returns (bytes32) {
return
keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256("1"),
block.chainid,
address(this)
)
);
}
/*//////////////////////////////////////////////////////////////
INTERNAL MINT/BURN LOGIC
//////////////////////////////////////////////////////////////*/
function _mint(address to, uint256 amount) internal virtual {
totalSupply += amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(address(0), to, amount);
}
function _burn(address from, uint256 amount) internal virtual {
balanceOf[from] -= amount;
// Cannot underflow because a user's balance
// will never be larger than the total supply.
unchecked {
totalSupply -= amount;
}
emit Transfer(from, address(0), amount);
}
}
lib/solmate/src/utils/SafeTransferLib.sol
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
import {ERC20} from "../tokens/ERC20.sol";
/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.
library SafeTransferLib {
/*//////////////////////////////////////////////////////////////
ETH OPERATIONS
//////////////////////////////////////////////////////////////*/
function safeTransferETH(address to, uint256 amount) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Transfer the ETH and store if it succeeded or not.
success := call(gas(), to, amount, 0, 0, 0, 0)
}
require(success, "ETH_TRANSFER_FAILED");
}
/*//////////////////////////////////////////////////////////////
ERC20 OPERATIONS
//////////////////////////////////////////////////////////////*/
function safeTransferFrom(
ERC20 token,
address from,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(from, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "from" argument.
mstore(add(freeMemoryPointer, 36), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(freeMemoryPointer, 68), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
// We use 100 because the length of our calldata totals up like so: 4 + 32 * 3.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
success := call(gas(), token, 0, freeMemoryPointer, 100, 0, 32)
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data and token has code.
if and(iszero(and(eq(mload(0), 1), gt(returndatasize(), 31))), success) {
success := iszero(or(iszero(extcodesize(token)), returndatasize()))
}
}
require(success, "TRANSFER_FROM_FAILED");
}
function safeTransfer(
ERC20 token,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
success := call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data and token has code.
if and(iszero(and(eq(mload(0), 1), gt(returndatasize(), 31))), success) {
success := iszero(or(iszero(extcodesize(token)), returndatasize()))
}
}
require(success, "TRANSFER_FAILED");
}
function safeApprove(
ERC20 token,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
success := call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data and token has code.
if and(iszero(and(eq(mload(0), 1), gt(returndatasize(), 31))), success) {
success := iszero(or(iszero(extcodesize(token)), returndatasize()))
}
}
require(success, "APPROVE_FAILED");
}
}
src/external/IGMTokenManager.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/**
* Ondo Global Markets token manager (mint + redeem).
*
* Vendored from dollarparking `contracts/src/OndoMinter.sol`; the redeem side
* mirrors the live Ondo GMTokenManager ABI (see the `Ondo API` project's
* `packages/core/src/contracts.ts` GM_TOKEN_MANAGER_ABI). The `Quote` tuple field
* ORDER is consensus-critical: the off-chain attestation signature is over exactly
* this layout (go-ethereum packs by order), and the bot's `Quote` struct mirrors
* it field-for-field. Do not reorder.
*/
interface IGMTokenManager {
struct Quote {
uint256 chainId;
uint256 attestationId;
bytes32 userId;
address asset; // the GM token Ondo mints/redeems; read to know what to forward
uint256 price;
uint256 quantity;
uint256 expiration;
uint8 side; // 0 = buy/mint, 1 = sell/redeem
bytes32 additionalData;
}
/// @notice Verifies the off-chain signature, pulls depositToken from
/// msg.sender, mints the GM asset to msg.sender. Reverts if the
/// attestation is expired (~30s window) or msg.sender's on-chain
/// userId != quote.userId (must be Ondo-whitelisted).
function mintWithAttestation(
Quote calldata quote,
bytes calldata signature,
address depositToken,
uint256 depositTokenAmount
) external returns (uint256);
/// @notice The redeem (sell) counterpart of `mintWithAttestation`: verifies the
/// off-chain signature, pulls `quote.quantity` of the GM asset
/// (`quote.asset`) from msg.sender, burns it, and sends `receiveToken`
/// (USDC) back to msg.sender — at least `minimumReceiveAmount` or it
/// reverts. Same expiry + userId-whitelist gating as mint
/// (`quote.side` must be 1). Returns the receiveToken amount paid out.
function redeemWithAttestation(
Quote calldata quote,
bytes calldata signature,
address receiveToken,
uint256 minimumReceiveAmount
) external returns (uint256);
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"forge-std/=lib/forge-std/src/",
"solmate/=lib/solmate/src/",
"ds-test/=lib/solmate/lib/ds-test/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.