Skip to content
Closed
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
11 changes: 7 additions & 4 deletions src/periphery/MidnightBundles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import {IERC20Permit} from "./interfaces/IERC20Permit.sol";
import {IPermit2} from "./interfaces/IPermit2.sol";
import {UtilsLib} from "../libraries/UtilsLib.sol";
import {IdLib} from "../libraries/IdLib.sol";
import {SafeTransferLib} from "../libraries/SafeTransferLib.sol";
import {TakeAmountsLib} from "./TakeAmountsLib.sol";
import {ConsumableUnitsLib} from "./ConsumableUnitsLib.sol";
Expand Down Expand Up @@ -43,9 +44,11 @@ contract MidnightBundles is IMidnightBundles {

address public constant PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;
address public immutable MIDNIGHT;
uint256 public immutable INITIAL_CHAIN_ID;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uint256 public immutable INITIAL_CHAIN_ID;
uint256 public immutable MIDNIGHT_INITIAL_CHAIN_ID;

(optional)


constructor(address _midnight) {
MIDNIGHT = _midnight;
INITIAL_CHAIN_ID = IMidnight(_midnight).INITIAL_CHAIN_ID();
}

/// EXTERNAL ///
Expand Down Expand Up @@ -80,7 +83,7 @@ contract MidnightBundles is IMidnightBundles {
uint256 filledBuyerAssets;
for (uint256 i; i < takes.length && filledUnits < targetUnits; i++) {
require(!takes[i].offer.buy, InconsistentSide());
require(IMidnight(MIDNIGHT).toId(takes[i].offer.market) == id, InconsistentMarket());
require(IdLib.toId(takes[i].offer.market, INITIAL_CHAIN_ID, MIDNIGHT) == id, InconsistentMarket());
uint256 unitsToTake = min(
targetUnits - filledUnits,
takes[i].units,
Expand Down Expand Up @@ -147,7 +150,7 @@ contract MidnightBundles is IMidnightBundles {
uint256 filledSellerAssets;
for (uint256 i; i < takes.length && filledUnits < targetUnits; i++) {
require(takes[i].offer.buy, InconsistentSide());
require(IMidnight(MIDNIGHT).toId(takes[i].offer.market) == id, InconsistentMarket());
require(IdLib.toId(takes[i].offer.market, INITIAL_CHAIN_ID, MIDNIGHT) == id, InconsistentMarket());
uint256 unitsToTake = min(
targetUnits - filledUnits,
takes[i].units,
Expand Down Expand Up @@ -204,7 +207,7 @@ contract MidnightBundles is IMidnightBundles {
uint256 filledBuyerAssets;
for (uint256 i; i < takes.length && filledBuyerAssets < targetFilledBuyerAssets; i++) {
require(!takes[i].offer.buy, InconsistentSide());
require(IMidnight(MIDNIGHT).toId(takes[i].offer.market) == id, InconsistentMarket());
require(IdLib.toId(takes[i].offer.market, INITIAL_CHAIN_ID, MIDNIGHT) == id, InconsistentMarket());
uint256 unitsToTake = min(
TakeAmountsLib.buyerAssetsToUnits(
MIDNIGHT, id, takes[i].offer, targetFilledBuyerAssets - filledBuyerAssets
Expand Down Expand Up @@ -275,7 +278,7 @@ contract MidnightBundles is IMidnightBundles {
uint256 filledSellerAssets;
for (uint256 i; i < takes.length && filledSellerAssets < targetFilledSellerAssets; i++) {
require(takes[i].offer.buy, InconsistentSide());
require(IMidnight(MIDNIGHT).toId(takes[i].offer.market) == id, InconsistentMarket());
require(IdLib.toId(takes[i].offer.market, INITIAL_CHAIN_ID, MIDNIGHT) == id, InconsistentMarket());
uint256 unitsToTake = min(
TakeAmountsLib.sellerAssetsToUnits(
MIDNIGHT, id, takes[i].offer, targetFilledSellerAssets - filledSellerAssets
Expand Down
1 change: 1 addition & 0 deletions src/periphery/interfaces/IMidnightBundles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface IMidnightBundles {
/// STORAGE GETTERS ///
function PERMIT2() external view returns (address);
function MIDNIGHT() external view returns (address);
function INITIAL_CHAIN_ID() external view returns (uint256);

// forgefmt: disable-start
/// FUNCTIONS ///
Expand Down