Verified contractExactMIT
SeaportAdvancedSource
Address0x34680ff721352bb8dc906090a56a6ef9d3b310fe
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.26
- Same code
Only this contract
Details
- Compiler
- solc 0.8.26+commit.8a97fa7a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- Via IR
- yes
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,408,705
- Creation transaction
- 0x7231380e62…6a097a2410
3 files
- src/nft/SeaportAdvancedSource.solmain11.84 KB
- src/nft/FloorVault.sol8.84 KB
- src/nft/SeaportSource.sol4.25 KB
src/nft/SeaportAdvancedSource.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import {IERC721} from "./FloorVault.sol";
import {IFloorSource} from "./SeaportSource.sol";
/// @dev Seaport 1.6 advanced order fulfilment. Enums are ABI-encoded as uint8, and are kept as uint8 here
/// so that an out-of-range value is refused by this adapter's own checks rather than by the decoder.
interface ISeaportAdvanced {
struct OfferItem {
uint8 itemType;
address token;
uint256 identifierOrCriteria;
uint256 startAmount;
uint256 endAmount;
}
struct ConsiderationItem {
uint8 itemType;
address token;
uint256 identifierOrCriteria;
uint256 startAmount;
uint256 endAmount;
address payable recipient;
}
struct OrderParameters {
address offerer;
address zone;
OfferItem[] offer;
ConsiderationItem[] consideration;
uint8 orderType;
uint256 startTime;
uint256 endTime;
bytes32 zoneHash;
uint256 salt;
bytes32 conduitKey;
uint256 totalOriginalConsiderationItems;
}
struct AdvancedOrder {
OrderParameters parameters;
uint120 numerator;
uint120 denominator;
bytes signature;
bytes extraData;
}
struct CriteriaResolver {
uint256 orderIndex;
uint8 side;
uint256 index;
uint256 identifier;
bytes32[] criteriaProof;
}
function fulfillAdvancedOrder(
AdvancedOrder calldata advancedOrder,
CriteriaResolver[] calldata criteriaResolvers,
bytes32 fulfillerConduitKey,
address recipient
) external payable returns (bool fulfilled);
}
/**
* @title SeaportAdvancedSource -- buy one NFT from a restricted (SignedZone) OpenSea listing.
*
* @notice Most of Robinhood Chain's OpenSea floor is not fillable as a basic order. OpenSea lists those
* collections through its SignedZone (SIP-7): the order is restricted, and Seaport only fills it
* with zone `extraData` that OpenSea signs, per request, for one named fulfiller and a few minutes.
* `fulfillBasicOrder` has nowhere to put that data, so `SeaportSource` cannot buy them. This adapter
* fills the same listings through `fulfillAdvancedOrder`, with the same promises as SeaportSource:
* the collection is fixed, the price is capped by the caller, the NFT ends up with the caller and so
* does every wei it did not spend. Whoever supplies the listing gets nothing and can take nothing.
*
* @dev ## Who fulfils, and who receives
*
* The *fulfiller* is this contract, necessarily. Seaport hands the zone `fulfiller = msg.sender`, and
* OpenSea's SignedZone (0x000056f7000000ece9003ca63978907a00ffd100) reverts `InvalidFulfiller` unless
* that equals the fulfiller its signature names (extraData bytes 1-21). Only this contract calls
* Seaport, so OpenSea's fulfillment data must be requested for this contract's address -- never the
* reserve's. test/RobinhoodAdvancedListing.fork.t.sol replays a real signature both ways.
*
* The *recipient* is the caller (the reserve), directly. The zone never sees the recipient -- it is
* not part of `ZoneParameters`, so no signature binds it -- and CollectionReserve only asks, after
* `buy` returns, whether it owns the token. Delivering straight to the caller rather than here and
* forwarding it matters for the collections OpenSea restricts: most of them are ERC721-C, whose
* transfer registry authorises exactly one transfer of that token id while the zone is inside the
* fill. A second hop out of this contract would lean on the collection still permitting direct
* (owner-initiated) transfers, which a collection owner can switch off at any time; a single hop does
* not. It also means an NFT is never held here, so none can be stranded here.
*
* ## What is enforced, whatever the listing, zone or extraData say
*
* - the order is not a CONTRACT order (whose offerer rewrites the items at fill time);
* - the offer is exactly one ERC-721 of `COLLECTION`, amount 1, no criteria;
* - every consideration item is native ETH, no token, no identifier; the price is the sum of each
* item's larger amount, so a declining listing is capped at its dearest point;
* - the price is at most `maxPrice` and at most `msg.value`, and Seaport is sent exactly that price,
* so nothing the zone, the offerer or a fee recipient does can make it spend more;
* - a full fill (1/1) with no criteria resolvers and no fulfiller conduit: payment is native, so the
* fulfiller has nothing for a conduit to move;
* - the caller did not own the token before and does after, measured with `ownerOf`;
* - `spent` is measured from this contract's balance, not read off the order, and everything left
* here -- change, Seaport's refund, anything forced in -- goes back to the caller;
* - one purchase at a time, and ETH is only accepted from Seaport while a purchase is in flight.
*
* ## Nothing can be kept here: no ETH withdrawal exists, and none is needed
*
* ETH: every purchase refunds or reverts, and `receive` refuses ETH from anyone but Seaport mid-fill. The
* only ETH that cannot be refused is ETH forced in (SELFDESTRUCT still moves a balance after EIP-6780);
* that is handed to the next caller along with its change, capped at what that call sent so the
* caller's balance accounting never goes negative -- a donation to whichever reserve buys next, recorded
* as a cheaper purchase. So nobody, the rescuer included, can ever withdraw ETH from this contract.
*
* NFTs: a purchase delivers straight to the caller, and `safeTransferFrom` in is refused (no receiver
* hook). A plain `transferFrom` cannot be refused, though, so an NFT can genuinely be sent here by mistake.
* For that one case the rescuer set at construction (transferable) may send an NFT out -- never while a
* purchase is in flight, so it can never touch the NFT being delivered.
*
* The zone and its extraData are passed through untouched: they decide whether Seaport fills the
* order at all, never what the order costs or where the NFT goes.
*/
contract SeaportAdvancedSource is IFloorSource {
error WrongCollection();
error NotNativeConsideration();
error UnsupportedOrder();
error TooExpensive(uint256 price, uint256 maxPrice);
error AlreadyOwned();
error FillFailed();
error NotReceived();
error RefundFailed();
error Reentrancy();
error UnexpectedETH();
error ExtraConsideration(uint256 items, uint256 original);
error NotRescuer();
error ZeroAddress();
event RescuerSet(address indexed rescuer);
event RescuedNFT(address indexed token, uint256 indexed id, address indexed to);
ISeaportAdvanced public constant SEAPORT = ISeaportAdvanced(0x0000000000000068F116a894984e2DB1123eB395);
IERC721 public immutable COLLECTION;
/// @notice May send out an NFT sent here by mistake. NFTs only; transferable; never during a purchase.
address public rescuer;
uint8 internal constant ITEM_NATIVE = 0;
uint8 internal constant ITEM_ERC721 = 2;
/// @dev FULL_OPEN 0, PARTIAL_OPEN 1, FULL_RESTRICTED 2, PARTIAL_RESTRICTED 3. CONTRACT (4) is refused.
uint8 internal constant MAX_ORDER_TYPE = 3;
uint256 private _lock = 1;
constructor(IERC721 collection, address rescuer_) {
if (rescuer_ == address(0)) revert ZeroAddress();
COLLECTION = collection;
rescuer = rescuer_;
emit RescuerSet(rescuer_);
}
/// @param maxPrice Hard cap on what may be spent, in wei.
/// @param data abi.encode(ISeaportAdvanced.AdvancedOrder), zone extraData signed for this contract.
function buy(uint256 maxPrice, bytes calldata data) external payable returns (uint256 id, uint256 spent) {
if (_lock != 1) revert Reentrancy();
_lock = 2;
ISeaportAdvanced.AdvancedOrder memory order = abi.decode(data, (ISeaportAdvanced.AdvancedOrder));
uint256 price;
(id, price) = _check(order.parameters);
if (price > maxPrice || price > msg.value) revert TooExpensive(price, maxPrice);
if (COLLECTION.ownerOf(id) == msg.sender) revert AlreadyOwned();
order.numerator = 1;
order.denominator = 1;
bool filled = SEAPORT.fulfillAdvancedOrder{value: price}(
order, new ISeaportAdvanced.CriteriaResolver[](0), bytes32(0), msg.sender
);
if (!filled) revert FillFailed();
if (COLLECTION.ownerOf(id) != msg.sender) revert NotReceived();
// Everything here goes back. Only ETH that came from this call can be charged to it, so anything
// beyond msg.value (forced in from outside) waits for the next purchase rather than reverting.
uint256 back = address(this).balance;
if (back > msg.value) back = msg.value;
spent = msg.value - back;
if (spent > maxPrice) revert TooExpensive(spent, maxPrice);
if (back != 0) {
(bool ok,) = msg.sender.call{value: back}("");
if (!ok) revert RefundFailed();
}
_lock = 1;
}
/// @dev The order's token id and its dearest price, or revert.
function _check(ISeaportAdvanced.OrderParameters memory p) internal view returns (uint256 id, uint256 price) {
if (p.orderType > MAX_ORDER_TYPE) revert UnsupportedOrder();
if (p.offer.length != 1) revert WrongCollection();
ISeaportAdvanced.OfferItem memory o = p.offer[0];
if (o.itemType != ITEM_ERC721 || o.token != address(COLLECTION) || o.startAmount != 1 || o.endAmount != 1) {
revert WrongCollection();
}
id = o.identifierOrCriteria;
// Only what the lister signed may be paid. Seaport lets the fulfiller append consideration items
// beyond `totalOriginalConsiderationItems` (tips), and every item here is priced into what the
// reserve pays -- so an appended item would be the caller paying themselves out of reserve cash,
// up to the floor. OpenSea's own fee items are part of the signed order, so they are original.
uint256 n = p.consideration.length;
if (n != p.totalOriginalConsiderationItems) revert ExtraConsideration(n, p.totalOriginalConsiderationItems);
for (uint256 i; i < n; ++i) {
ISeaportAdvanced.ConsiderationItem memory c = p.consideration[i];
if (c.itemType != ITEM_NATIVE || c.token != address(0) || c.identifierOrCriteria != 0) {
revert NotNativeConsideration();
}
price += c.startAmount > c.endAmount ? c.startAmount : c.endAmount;
}
}
/// @dev Seaport returns unspent ETH to its caller mid-fill; nothing else may send ETH here.
receive() external payable {
if (_lock != 2 || msg.sender != address(SEAPORT)) revert UnexpectedETH();
}
// ------------------------------------------------------------------ rescue (a stray NFT, nothing else)
modifier onlyRescuerIdle() {
if (msg.sender != rescuer) revert NotRescuer();
if (_lock != 1) revert Reentrancy();
_;
}
function setRescuer(address next) external onlyRescuerIdle {
if (next == address(0)) revert ZeroAddress();
rescuer = next;
emit RescuerSet(next);
}
function rescueNFT(address token, uint256 id, address to) external onlyRescuerIdle {
if (to == address(0)) revert ZeroAddress();
IERC721(token).transferFrom(address(this), to, id);
emit RescuedNFT(token, id, to);
}
}
src/nft/FloorVault.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
interface IERC721 {
function ownerOf(uint256 id) external view returns (address);
function safeTransferFrom(address from, address to, uint256 id) external;
function transferFrom(address from, address to, uint256 id) external;
function name() external view returns (string memory);
function symbol() external view returns (string memory);
}
/**
* @title FloorVault -- one NFT collection, one fungible floor token.
* @notice Deposit any NFT from the collection and receive SHARES_PER_NFT tokens. Burn that many and
* take any NFT out. The token therefore trades at the collection's floor, which is exactly
* what a launchpad needs as a quote asset: a coin "paired with Pudgy Penguins" is a pool
* against this token, and whoever gathers a whole NFT's worth of it can redeem a penguin.
*
* Deliberately minimal. No rebasing, no fee-on-transfer, plain 18-decimal ERC20 so every DEX,
* bridge gateway and oracle treats it as an ordinary token. Fees are taken in shares and sent to
* `feeRecipient`, so the share-per-NFT ratio never drifts. A direct `safeTransferFrom` into the
* vault also mints, so wallets that only know how to "send" still work.
*/
contract FloorVault {
// ------------------------------------------------------------------ erc20
string public name;
string public symbol;
uint8 public constant decimals = 18;
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
// ------------------------------------------------------------------ vault
error NotFactory();
error WrongCollection();
error Empty();
error NotHeld(uint256 id);
error FeeTooHigh();
error InsufficientShares();
event Deposited(address indexed from, uint256[] ids, uint256 sharesOut, uint256 fee);
event Redeemed(address indexed to, uint256[] ids, uint256 sharesIn, uint256 fee);
event FeesUpdated(uint16 mintFeeBps, uint16 redeemFeeBps, address feeRecipient);
uint256 public constant SHARES_PER_NFT = 1_000_000e18;
uint16 public constant MAX_FEE_BPS = 500; // 5%
IERC721 public immutable COLLECTION;
address public immutable FACTORY;
uint16 public mintFeeBps;
uint16 public redeemFeeBps;
address public feeRecipient;
/// @dev Enumerable holdings so a frontend can show what is redeemable.
uint256[] private _held;
mapping(uint256 id => uint256 indexPlusOne) private _heldIndex;
bool private _depositing;
constructor(
IERC721 collection,
string memory name_,
string memory symbol_,
address feeRecipient_,
uint16 mintFeeBps_,
uint16 redeemFeeBps_
) {
if (mintFeeBps_ > MAX_FEE_BPS || redeemFeeBps_ > MAX_FEE_BPS) revert FeeTooHigh();
COLLECTION = collection;
FACTORY = msg.sender;
name = name_;
symbol = symbol_;
feeRecipient = feeRecipient_;
mintFeeBps = mintFeeBps_;
redeemFeeBps = redeemFeeBps_;
}
// ------------------------------------------------------------------ views
function held() external view returns (uint256[] memory) {
return _held;
}
function heldCount() external view returns (uint256) {
return _held.length;
}
function isHeld(uint256 id) public view returns (bool) {
return _heldIndex[id] != 0;
}
/// @notice Shares needed to redeem `n` NFTs, fee included.
function sharesToRedeem(uint256 n) public view returns (uint256) {
uint256 base = SHARES_PER_NFT * n;
return base + (base * redeemFeeBps) / 10_000;
}
/// @notice Shares received for depositing `n` NFTs, after the mint fee.
function sharesForDeposit(uint256 n) public view returns (uint256) {
uint256 base = SHARES_PER_NFT * n;
return base - (base * mintFeeBps) / 10_000;
}
// ------------------------------------------------------------------ deposit / redeem
/// @notice Pull `ids` from the caller (needs approval) and mint shares to them.
function deposit(uint256[] calldata ids) external returns (uint256 sharesOut) {
return depositTo(ids, msg.sender);
}
function depositTo(uint256[] calldata ids, address to) public returns (uint256 sharesOut) {
if (ids.length == 0) revert Empty();
_depositing = true;
for (uint256 i; i < ids.length; ++i) {
COLLECTION.transferFrom(msg.sender, address(this), ids[i]);
_add(ids[i]);
}
_depositing = false;
sharesOut = _mintFor(to, ids.length);
emit Deposited(msg.sender, ids, sharesOut, SHARES_PER_NFT * ids.length - sharesOut);
}
/// @notice Burn shares and take the named NFTs out.
function redeem(uint256[] calldata ids) external {
redeemTo(ids, msg.sender);
}
function redeemTo(uint256[] calldata ids, address to) public {
if (ids.length == 0) revert Empty();
uint256 cost = sharesToRedeem(ids.length);
uint256 base = SHARES_PER_NFT * ids.length;
if (balanceOf[msg.sender] < cost) revert InsufficientShares();
_burn(msg.sender, base);
if (cost > base) _transfer(msg.sender, feeRecipient, cost - base);
for (uint256 i; i < ids.length; ++i) {
if (!isHeld(ids[i])) revert NotHeld(ids[i]);
_remove(ids[i]);
COLLECTION.transferFrom(address(this), to, ids[i]);
}
emit Redeemed(to, ids, cost, cost - base);
}
/// @dev A plain `safeTransferFrom` into the vault counts as a deposit for whoever sent it.
function onERC721Received(address operator, address from, uint256 id, bytes calldata) external returns (bytes4) {
if (msg.sender != address(COLLECTION)) revert WrongCollection();
if (!_depositing) {
_add(id);
address to = from == address(0) ? operator : from;
uint256[] memory ids = new uint256[](1);
ids[0] = id;
uint256 out = _mintFor(to, 1);
emit Deposited(to, ids, out, SHARES_PER_NFT - out);
}
return this.onERC721Received.selector;
}
// ------------------------------------------------------------------ admin (factory-owned)
function setFees(uint16 mintFeeBps_, uint16 redeemFeeBps_, address feeRecipient_) external {
if (msg.sender != FACTORY) revert NotFactory();
if (mintFeeBps_ > MAX_FEE_BPS || redeemFeeBps_ > MAX_FEE_BPS) revert FeeTooHigh();
mintFeeBps = mintFeeBps_;
redeemFeeBps = redeemFeeBps_;
feeRecipient = feeRecipient_;
emit FeesUpdated(mintFeeBps_, redeemFeeBps_, feeRecipient_);
}
// ------------------------------------------------------------------ internals
function _mintFor(address to, uint256 n) internal returns (uint256 out) {
uint256 base = SHARES_PER_NFT * n;
out = sharesForDeposit(n);
_mint(to, out);
if (base > out) _mint(feeRecipient, base - out);
}
function _add(uint256 id) internal {
_held.push(id);
_heldIndex[id] = _held.length;
}
function _remove(uint256 id) internal {
uint256 idx = _heldIndex[id] - 1;
uint256 last = _held[_held.length - 1];
_held[idx] = last;
_heldIndex[last] = idx + 1;
_held.pop();
delete _heldIndex[id];
}
function _mint(address to, uint256 amount) internal {
totalSupply += amount;
balanceOf[to] += amount;
emit Transfer(address(0), to, amount);
}
function _burn(address from, uint256 amount) internal {
balanceOf[from] -= amount;
totalSupply -= amount;
emit Transfer(from, address(0), amount);
}
function _transfer(address from, address to, uint256 amount) internal {
balanceOf[from] -= amount;
balanceOf[to] += amount;
emit Transfer(from, to, amount);
}
function transfer(address to, uint256 amount) external returns (bool) {
_transfer(msg.sender, to, amount);
return true;
}
function approve(address spender, uint256 amount) external returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transferFrom(address from, address to, uint256 amount) external returns (bool) {
uint256 a = allowance[from][msg.sender];
if (a != type(uint256).max) allowance[from][msg.sender] = a - amount;
_transfer(from, to, amount);
return true;
}
}
src/nft/SeaportSource.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import {IERC721} from "./FloorVault.sol";
/// @notice A venue the reserve can buy one NFT from. Receives ETH, returns the NFT to the caller.
interface IFloorSource {
/// @param maxPrice Hard cap on what may be spent, in wei. msg.value is at least this.
/// @param data Venue-specific: a signed listing, a pool address, etc.
/// @return id The NFT delivered to msg.sender.
/// @return spent ETH actually spent; the rest is returned to msg.sender.
function buy(uint256 maxPrice, bytes calldata data) external payable returns (uint256 id, uint256 spent);
}
/// @dev Seaport 1.6 basic order fulfilment, ETH for one ERC721.
interface ISeaport {
struct AdditionalRecipient {
uint256 amount;
address payable recipient;
}
struct BasicOrderParameters {
address considerationToken;
uint256 considerationIdentifier;
uint256 considerationAmount;
address payable offerer;
address zone;
address offerToken;
uint256 offerIdentifier;
uint256 offerAmount;
uint8 basicOrderType;
uint256 startTime;
uint256 endTime;
bytes32 zoneHash;
uint256 salt;
bytes32 offererConduitKey;
bytes32 fulfillerConduitKey;
uint256 totalOriginalAdditionalRecipients;
AdditionalRecipient[] additionalRecipients;
bytes signature;
}
function fulfillBasicOrder_efficient_6GL6yc(BasicOrderParameters calldata p) external payable returns (bool);
}
/**
* @title SeaportSource -- buy one NFT from any live OpenSea listing.
* @notice OpenSea, and most of the market, is Seaport. Listings are signed off-chain and anyone can
* fill them on-chain, so this adapter turns "a live listing at or under the floor" into an
* atomic purchase by the reserve. Whoever supplies the listing -- a bot, the app bundling it
* into a buyer's transaction, a holder filling their own -- gets nothing and can take nothing:
* the price is capped by the caller, the collection is fixed, and the NFT goes to the caller.
*/
contract SeaportSource is IFloorSource {
error WrongCollection();
error TooExpensive(uint256 price, uint256 maxPrice);
error FillFailed();
error NotReceived();
error RefundFailed();
error ExtraRecipients(uint256 recipients, uint256 original);
ISeaport public constant SEAPORT = ISeaport(0x0000000000000068F116a894984e2DB1123eB395);
IERC721 public immutable COLLECTION;
constructor(IERC721 collection) {
COLLECTION = collection;
}
function buy(uint256 maxPrice, bytes calldata data) external payable returns (uint256 id, uint256 spent) {
ISeaport.BasicOrderParameters memory p = abi.decode(data, (ISeaport.BasicOrderParameters));
if (p.offerToken != address(COLLECTION) || p.offerAmount != 1) revert WrongCollection();
// Only recipients the lister signed may be paid: Seaport lets the fulfiller append tip recipients
// past `totalOriginalAdditionalRecipients`, and they would be priced into what the reserve pays.
if (p.additionalRecipients.length != p.totalOriginalAdditionalRecipients) {
revert ExtraRecipients(p.additionalRecipients.length, p.totalOriginalAdditionalRecipients);
}
spent = p.considerationAmount;
for (uint256 i; i < p.additionalRecipients.length; ++i) {
spent += p.additionalRecipients[i].amount;
}
if (spent > maxPrice || spent > msg.value) revert TooExpensive(spent, maxPrice);
id = p.offerIdentifier;
if (!SEAPORT.fulfillBasicOrder_efficient_6GL6yc{value: spent}(p)) revert FillFailed();
if (COLLECTION.ownerOf(id) != address(this)) revert NotReceived();
COLLECTION.transferFrom(address(this), msg.sender, id);
uint256 change = msg.value - spent;
if (change != 0) {
(bool ok,) = msg.sender.call{value: change}("");
if (!ok) revert RefundFailed();
}
}
function onERC721Received(address, address, uint256, bytes calldata) external pure returns (bytes4) {
return this.onERC721Received.selector;
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"forge-std/=lib/forge-std/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.