Skip to content

Commit

Permalink
Use IArbSys for Arbitrum block number fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongeric committed Sep 30, 2024
1 parent b0cd19a commit 5b1d81d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/interfaces/IArbSys.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

/**
* @notice Minimal interface for interacting with Arbitrum system contracts
*/
interface IArbSys {
/**
* @notice Get Arbitrum block number (distinct from L1 block number; Arbitrum genesis block has block number 0)
* @return block number as int
*/
function arbBlockNumber() external view returns (uint256);
}
8 changes: 7 additions & 1 deletion src/lib/ExclusivityLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.0;

import {FixedPointMathLib} from "solmate/src/utils/FixedPointMathLib.sol";
import {ResolvedOrder, OutputToken} from "../base/ReactorStructs.sol";
import {IArbSys} from "../interfaces/IArbSys.sol";

/// @title ExclusiveOverride
/// @dev This library handles order exclusivity
Expand Down Expand Up @@ -42,7 +43,12 @@ library ExclusivityLib {
uint256 exclusivityEnd,
uint256 exclusivityOverrideBps
) internal view {
_handleExclusiveOverride(order, exclusive, exclusivityEnd, exclusivityOverrideBps, block.number);
uint256 blockNumber = block.number;
// Arbitrum specific block numbers must be fetched from their system contracts
if (block.chainid == 42161) {
blockNumber = IArbSys(address(100)).arbBlockNumber();
}
_handleExclusiveOverride(order, exclusive, exclusivityEnd, exclusivityOverrideBps, blockNumber);
}

/// @notice Applies exclusivity override to the resolved order if necessary
Expand Down
13 changes: 11 additions & 2 deletions src/lib/NonlinearDutchDecayLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {FixedPointMathLib} from "solmate/src/utils/FixedPointMathLib.sol";
import {MathExt} from "./MathExt.sol";
import {Uint16ArrayLibrary, Uint16Array, fromUnderlying} from "../types/Uint16Array.sol";
import {DutchDecayLib} from "./DutchDecayLib.sol";
import {IArbSys} from "../interfaces/IArbSys.sol";

/// @notice helpers for handling non-linear dutch order objects
library NonlinearDutchDecayLib {
Expand All @@ -21,6 +22,8 @@ library NonlinearDutchDecayLib {
/// @param curve The curve to search
/// @param startAmount The absolute start amount
/// @param decayStartBlock The absolute start block of the decay
/// @param minAmount The minimum amount to decay to
/// @param maxAmount The maximum amount to decay to
/// @dev Expects the relativeBlocks in curve to be strictly increasing
function decay(
NonlinearDutchDecay memory curve,
Expand All @@ -34,12 +37,18 @@ library NonlinearDutchDecayLib {
revert InvalidDecayCurve();
}

uint256 blockNumber = block.number;
// Arbitrum specific block numbers must be fetched from their system contracts
if (block.chainid == 42161) {
blockNumber = IArbSys(address(100)).arbBlockNumber();
}

// handle current block before decay or no decay
if (decayStartBlock >= block.number || curve.relativeAmounts.length == 0) {
if (decayStartBlock >= blockNumber || curve.relativeAmounts.length == 0) {
return startAmount.bound(minAmount, maxAmount);
}

uint16 blockDelta = uint16(block.number - decayStartBlock);
uint16 blockDelta = uint16(blockNumber - decayStartBlock);
(uint16 startPoint, uint16 endPoint, int256 relStartAmount, int256 relEndAmount) =
locateCurvePosition(curve, blockDelta);
// get decay of only the relative amounts
Expand Down

0 comments on commit 5b1d81d

Please sign in to comment.