Skip to main content

Restricted Swap

Overview​

RestrictedSwap provides a secure means of swapping tokens between known holders of the primary Restricted token and any payment ERC-20 tokens (ie USDC, DAI, etc).

Note: Restricted Swap is not intended between two Restricted tokens. Rather, it is intended as a purchase of Restricted tokens using ERC-20 tokens (AKA payment token or quote token). This is enforced in the Restricted Swap contract itself, by preventing ERC-1404 compatible tokens (checked via ERC-165 interface support) from being used as payment. However, other types of Restricted tokens may not explicitly support the ERC-1404 interface and thus cannot be checked programmatically; therefore, this functionality should be used with caution and payment token types should always be verified first.

Usage​

How It Works​

As a prerequisite, users of the swap functionality are assumed to have passed any necessary off-chain AML/KYC and deemed valid holders. Contracts are also assumed to have been configured properly with admin-granted roles and transfer restrictions in place.

Configuring a Purchase of Restricted Token​

As a holder (Buyer) of an ERC-20 payment token (ie USDC, DAI, etc), one can configure a purchase order for a specified amount of Restricted token with a known party (Seller). Here is an example involving USDC:

  1. Buyer must know in advance specifically how much Restricted token they'd like to receive, how much USDC they are willing to pay, and the Seller on the other end.
  2. Buyer must approve the Swap contract itself to handle their USDC in the purchase amount required.
  3. Buyer then configures an open purchase order by calling configureBuy with the following parameters. A Swap ID is emitted in an event.
    • amount of Restricted token desired
    • address of Seller
    • address of payment token contract
    • amount of payment token (USDC) willing to swap
    • deadline for swap expiration (required; must be in the future and within the contract's maxSwapLifetime)
    • minimum fill amount (must be 0 for this closed order)
  4. Seller must approve the Swap contract itself to handle their Restricted token in the sell amount required by the configured swap.
  5. Seller can complete this order by calling completeSwapWithRestrictedToken with the emitted Swap ID (passing 0 for the optional parent sell offer, since this bid does not draw from one).

When transfer restrictions are validated between Buyer and Seller, the swap is completed and assets are actually transferred between transacting parties.

Note: Role checks (e.g., pausing, admin-only operations) are resolved through the pre-deployed AccessControl contract referenced by the Restricted token and ancillary contracts.

Configuring a Sale of Restricted Token​

As a holder of the Restricted token, one can also configure a sell order for a specified amount of desired payment ERC-20 token. It is extremely similar to the example above, except terms of the sale must be specified in advance. Here is an example involving USDC:

  1. Seller must know in advance specifically how much Restricted token they'd like to sell, how much USDC they require, and the Buyer on the other end.
  2. Seller must approve the Swap contract itself to handle their Restricted token in the sell amount desired.
  3. Seller then configures an open sell order by calling configureSell with the following parameters. A Swap ID is emitted in an event.
    • amount of Restricted token to sell
    • address of payment token contract
    • address of Buyer
    • amount of payment token (USDC) required
    • deadline for swap expiration (required; must be in the future and within the contract's maxSwapLifetime)
    • minimum fill amount (must be 0 for this closed order)
  4. Buyer must approve the Swap contract itself to handle their USDC in the amount specified by the configured swap.
  5. Buyer can complete this order by calling completeSwapWithQuoteToken with the emitted Swap ID.

When transfer restrictions are validated between Buyer and Seller, the swap is completed and assets are actually transferred between transacting parties.

Open Orders and Partial Fills​

In addition to the closed (named-counterparty) swap flows above, RestrictedSwap supports open orders that any compliant counterparty can fill, with optional partial fills so a single listing can be consumed by multiple takers.

How It Works​

  • Open Sell Order: call configureSell(...) with quoteTokenSender = address(0). The seller's restricted-token reservation is recorded in the advisory ledger (requiredAllowance), and any compliant buyer can call takeOpenSell(swapNumber, fillAmount) (or takeOpenSellWithPermit(...) to bundle ERC-2612 approval) to settle.
  • Open Buy Order: symmetric — call configureBuy(...) with restrictedTokenSender = address(0). The buyer's quote-token reservation is recorded in the same ledger, and any compliant holder may call takeOpenBuy(...) / takeOpenBuyWithPermit(...).

Compliance (detectTransferRestriction) is deferred to take time for open orders because the counterparty is unknown at configure time. The check runs against the actual taker before the transfer.

Partial Fills​

Takers may specify a fillAmount less than the remaining restricted-token amount. The pro-rata quote charge is computed as quoteTokenAmount * fillAmount / restrictedTokenAmount and must be a whole number — the contract reverts RestrictedSwap_AmountNotDivisible on any fillAmount that does not divide cleanly into the price ratio. This rules out rounding entirely: every fill pays its exact pro-rata share, no taker can ever overpay or underpay by even one wei, and no inventory can be siphoned via dust-fill griefing.

This is a product rule. The maker sets a fixed price. Each fill, decrease, increase and linked parent deduction uses exactly that price. The contract never rounds a quote amount. If an amount does not give a whole quote amount at the price, the call reverts.

⚠️ Pick listing amounts with a large GCD​

Because the pro-rata charge must be exact, the set of valid fillAmount values for a listing is fixed by the GCD of quoteTokenAmount and restrictedTokenAmount:

Valid fillAmount ∈ multiples of restrictedTokenAmount / gcd(quoteTokenAmount, restrictedTokenAmount), up to remainingRestrictedTokenAmount.

Listing (restricted / quote)GCDSmallest valid fillOutcome
1000 RLT for 100 USDC10010 RLTUp to 100 partial fills possible
1000 RLT for 250 USDC2504 RLTUp to 250 partial fills possible
1000 RLT for 7 USDC11000 RLT❗ Effectively no partial fills — only a full take works
997 RLT for 11 USDC (both prime)1997 RLT❗ Coprime — only a full take works

Coprime amounts silently force a single full-listing take. Sellers/buyers configuring open orders should:

  1. Round listing amounts to ratios with a large GCD (e.g. multiples of 10 / 100 / 1000 of the smaller side), or
  2. Accept that the listing is take-it-or-leave-it.

Off-chain orderbook UIs SHOULD validate the listing's GCD at configure time and surface a warning. configureSell / configureBuy do not reject coprime amounts, because a take-it-or-leave-it listing is valid.

The minimum fill must be a valid fill​

At configure time, the contract rejects a minimumFillAmount that is not a valid fill. If minimumFillAmount is not 0, quoteTokenAmount * minimumFillAmount must be a multiple of restrictedTokenAmount. Else the call reverts with RestrictedSwap_InvalidMinimumFillAmount. Thus a taker can always fill exactly the minimum while the remaining amount is at or above it.

  • minimumFillAmount = 0: no minimum.
  • minimumFillAmount = restrictedTokenAmount: the order is all-or-nothing. This is always valid.
  • Other values: use a multiple of restrictedTokenAmount / gcd(quoteTokenAmount, restrictedTokenAmount).
Listing (restricted / quote)Valid minimumRejected minimum
1000 RLT for 100 USDC0, 10, 20, …, 100015
1000 RLT for 7 USDC0, 1000100

Cancellation refunds only the remaining unfilled amount, not the original; already-filled portions are not reversed.

The Reservation Ledger Is Advisory​

The contract holds no escrow. At configure time and at increase time it records a reservation per maker and token in requiredAllowance, and it checks that the real allowance and balance of the maker cover all reservations at that moment. After that, the maker keeps control of the real allowance and balance. A maker can lower the allowance, move the balance, or spend the allowance in another contract, and the order stays active. The ledger therefore shows what the maker promised, not what the maker can deliver.

A user interface prunes such an order with two views:

  • makerCoverage(maker, token) returns the reserved amount, the real allowance to the swap contract and the real balance of the maker in that token.
  • isFillable(swapNumber) returns true when each named party of an active order covers its remaining leg with its real allowance and balance. A complete, canceled or expired order is not fillable.

At settlement time, each path checks the balance and the allowance of each party before any transfer. A short balance reverts with RestrictedSwap_InsufficientRestrictedTokenAmount or RestrictedSwap_InsufficientQuoteTokenAmount. A short allowance reverts with RestrictedSwap_InsufficientRestrictedTokenAllowance or RestrictedSwap_InsufficientQuoteTokenAllowance. The taker still pays the gas of the reverted transaction. Only an escrow would remove that cost, and the contract is escrowless by design.

Self-Fill Disallowed​

A configurer cannot also be the counterparty to their own open order. takeOpenSell reverts with RestrictedSwap_SelfFillNotAllowed when _msgSender() == swap.restrictedTokenSender; takeOpenBuy reverts the same way when _msgSender() == swap.quoteTokenSender. This prevents wash fills, misleading OpenSwapFilled events, and using takeOpen* as a cheaper substitute for cancelSwap. Configurers who want to retire an unfilled listing must call cancelSwap.

Events​

Each partial OR final fill emits:

OpenSwapFilled(swapNumber, filler, fillRestrictedAmount, fillQuoteAmount, remainingRestrictedAmount)

remainingRestrictedAmount == 0 indicates the order is now fully filled and its status is Complete. The same transaction then emits SwapComplete with the settled totals: the sum of the fills, and its quote at the configured price. The open side of the event is address(0), as in SwapConfigured. Read each filler of the OpenSwapFilled events as a counterparty.

SwapComplete(swapNumber, seller, settledRestricted, address(0), quoteToken, settledQuote, deadline)   // open sell
SwapComplete(swapNumber, address(0), settledRestricted, buyer, quoteToken, settledQuote, deadline) // open buy

Indexer Notes​

  • An open order is recognizable by SwapConfigured carrying quoteTokenSender == address(0) (open sell) or restrictedTokenSender == address(0) (open buy).
  • A single open order may emit multiple OpenSwapFilled events. If takers fill the full order, the last one carries remainingRestrictedAmount == 0, and SwapComplete follows in the same transaction. An order can also end by cancelSwap, by a decreaseOrder to 0, or by a parent-offer deduction to 0. Then the order emits SwapCanceled and no SwapComplete, and its last fill, if any, carries a remainingRestrictedAmount above 0. An expired order emits no event. Its status stays SellConfigured or BuyConfigured until a cancelSwap or a decreaseOrder to 0. A parent-offer deduction to 0 also ends an expired open sell, because the deduction does not check the deadline of the parent.
  • SwapComplete of an open order carries the settled totals and address(0) on the open side. The sum of the OpenSwapFilled amounts of the order is equal to these totals. A parent-offer deduction is a resize of the parent, not a fill, and the child swap reports its tokens. After a resize, these totals differ from the amounts in SwapConfigured. The view settledRestrictedTokenAmount(swapNumber) returns the restricted total at any time.
  • Off-chain orderbooks coordinating concurrent takers should serialize submissions per listing (SELECT FOR UPDATE) to avoid racing on the same on-chain remaining amount; lost races revert with RestrictedSwap_InvalidFillAmount or RestrictedSwap_AlreadyCompleted.

View Helpers​

  • remainingRestrictedTokenAmount(swapNumber) — current unfilled restricted amount. On a Complete swap this is always 0; a Canceled swap keeps the unfilled tail as history, so pair it with swapStatus before treating a non-zero value as available inventory.
  • settledRestrictedTokenAmount(swapNumber) — restricted amount that the fills transferred. For an open order, the value is equal to the sum of the OpenSwapFilled amounts of the order, also after a cancel. On a Complete open order, the value is equal to the restrictedTokenAmount of its SwapComplete event. A closed swap reports 0 before completion and its configured amount after completion.
  • isOpenOrder(swapNumber) — true if the swap has a zero counterparty (open) and must be filled via takeOpenSell / takeOpenBuy.

Deadline Functionality​

Every swap carries a mandatory deadline that automatically expires it after a specified timestamp. This prevents indefinitely active orders and bounds how long allowances stay reserved:

  • Required Deadline: deadline must be > 0 at configure time — the "no deadline" (0) sentinel is rejected with RestrictedSwap_DeadlineRequired.
  • Must Be In The Future: A deadline in the past reverts with RestrictedSwap_SwapExpired at configure time.
  • Bounded Horizon: deadline - block.timestamp must not exceed the contract's immutable maxSwapLifetime, or configuration reverts with RestrictedSwap_DeadlineExceedsMaxLifetime. maxSwapLifetime is fixed at deployment within [MIN_SWAP_LIFETIME_LIMIT, MAX_SWAP_LIFETIME_LIMIT].
  • Automatic Expiration: Once a swap's deadline passes, it becomes invalid and cannot be completed or filled.
  • Anyone Can Cancel Expired Swaps: Once a swap expires, anyone can cancel it to free up allowances.

Key Features:

  • Deadline is checked during swap completion - expired swaps cannot be completed
  • Expired swaps can be canceled by anyone, not just the original parties
  • The isSwapExpired() function allows checking if a swap has expired
  • All swap events include the deadline parameter for transparency

EIP-2612 Permit Helpers​

Each ...WithPermit function does an EIP-2612 permit and its operation in one transaction. Thus the caller signs one ERC-2771 forward request and does not send a separate approve first.

The value of permitValue​

permitValue is the value that the caller signed. The contract gives it to permit with no change. It does not calculate the value again on-chain.

An EIP-2612 signature is valid only for the exact signed value. The reservations of the caller can change before the transaction executes. For example, a different address can fill a different open order of the caller. Thus a value that the contract calculates from the reservations can be different from the signed value, and the permit then fails.

Calculate the value off-chain:

permitValue = requiredAllowance(caller, token) + <the amount of this operation>

permit replaces the allowance. It does not add to the allowance. These rules apply:

  • Include the current reservations. A value for this operation only removes the allowance for the other active orders of the caller. Then a taker cannot fill these orders, and the allowance is less than requiredAllowance.
  • The contract examines the requirement when the transaction executes. permitValue must be equal to or more than the requirement at that time. After the permit, the contract examines the allowance again. If the allowance is not sufficient, the call reverts with RestrictedSwap_Insufficient{Quote,Restricted}TokenAllowanceAfterPermit. Thus a value above the requirement is the safe choice when the other orders can change.
  • A value much above the requirement has a cost. For example, with type(uint256).max the caller gives more allowance than the open orders need.
  • The contract does not call permit when the allowance is sufficient. Thus a value for exactly the requirement cannot decrease an allowance that the caller set to a higher value. The nonce of the signature stays unused.
  • A front-runner cannot make the call fail with the same signature. The permit call is in a try/catch, and the allowance check follows it. If a front-runner sends the signature first and uses the nonce, the operation continues.

API Reference​

Constructor​

constructor(address restrictedLockupTokenAddress_, address trustedForwarder_, address accessControl_, uint256 maxSwapLifetime_)​

Initializes the RestrictedSwap contract with configuration parameters.

Parameters:

  • restrictedLockupTokenAddress_ (address): The RestrictedLockupToken contract address
  • trustedForwarder_ (address): ERC-2771 trusted forwarder address for meta-transactions
  • accessControl_ (address): AccessControl contract address for role management
  • maxSwapLifetime_ (uint256): Maximum allowed distance between block.timestamp and a swap's deadline at configure time, fixed for the life of the contract

Requirements:

  • All addresses must be non-zero
  • Access control address must be valid
  • maxSwapLifetime_ must be within [MIN_SWAP_LIFETIME_LIMIT, MAX_SWAP_LIFETIME_LIMIT], else RestrictedSwap_InvalidMaxSwapLifetime

Administrative Functions​

pause(bool isPaused_)​

Pauses or unpauses the contract functionality.

Parameters:

  • isPaused_ (bool): True to pause, false to unpause

Requirements:

  • Caller must have CONTRACT_ADMIN_ROLE or TRANSFER_ADMIN_ROLE

Emits: Paused(account) or Unpaused(account)


Swap Configuration Functions​

configureSell(uint256 restrictedTokenAmount, address quoteToken, address quoteTokenSender, uint256 quoteTokenAmount, uint256 deadline, uint256 minimumFillAmount)​

Configures a sell order for restricted tokens in exchange for quote tokens.

Parameters:

  • restrictedTokenAmount (uint256): Amount of restricted tokens to sell
  • quoteToken (address): Address of the quote token (ERC-20) to receive
  • quoteTokenSender (address): Address that will provide the quote tokens, or address(0) to create an open sell order any compliant buyer can fill via takeOpenSell
  • quoteTokenAmount (uint256): Amount of quote tokens to receive
  • deadline (uint256): Unix timestamp deadline for swap expiration (required; see Deadline Functionality)
  • minimumFillAmount (uint256): Minimum restricted-token amount a taker must fill on an open order via takeOpenSell (unless taking the entire remaining amount); 0 means no minimum. Must be 0 for closed swaps.

Requirements:

  • Contract must not be paused
  • Quote token must not be zero address
  • Caller's restricted token balance must cover all active sell orders plus this amount, else RestrictedSwap_InsufficientRestrictedTokenAmount
  • Caller must have sufficient restricted token allowance for this contract (all active sell orders plus this amount)
  • Quote token must not support ERC-1404 interface (to prevent restricted token swaps)
  • deadline must be > 0, not in the past, and within maxSwapLifetime
  • minimumFillAmount must be <= restrictedTokenAmount, and must be 0 when quoteTokenSender is a concrete address (closed swap)
  • If minimumFillAmount is not 0, quoteTokenAmount * minimumFillAmount must be a multiple of restrictedTokenAmount (see Partial Fills), else RestrictedSwap_InvalidMinimumFillAmount

The balance check uses balanceOf, so tokens with a timelock count. An expired sell order counts until someone cancels it. The contract checks the balance only at configure time and at an increase. If the seller transfers tokens later, a fill or a completion reverts with RestrictedSwap_InsufficientRestrictedTokenAmount.

For a closed sell, the transfer probe also rejects an order that the unlocked balance of the seller does not cover. For an open sell, the probe runs at fill time, because the taker is unknown. Thus a seller can list an open sell that the unlocked balance does not cover. A fill above the unlocked balance reverts with SENDER TOKENS LOCKED.

Emits: SwapConfigured(swapNumber, restrictedTokenSender, restrictedTokenAmount, quoteToken, quoteTokenSender, quoteTokenAmount, deadline, minimumFillAmount)


configureBuy(uint256 restrictedTokenAmount, address restrictedTokenSender, address quoteToken, uint256 quoteTokenAmount, uint256 deadline, uint256 minimumFillAmount)​

Configures a buy order for restricted tokens using quote tokens.

Parameters:

  • restrictedTokenAmount (uint256): Amount of restricted tokens to buy
  • restrictedTokenSender (address): Address that will provide the restricted tokens, or address(0) to create an open buy order any compliant holder can fill via takeOpenBuy
  • quoteToken (address): Address of the quote token (ERC-20) to pay with
  • quoteTokenAmount (uint256): Amount of quote tokens to pay
  • deadline (uint256): Unix timestamp deadline for swap expiration (required; see Deadline Functionality)
  • minimumFillAmount (uint256): Minimum restricted-token amount a taker must fill on an open order via takeOpenBuy (unless taking the entire remaining amount); 0 means no minimum. Must be 0 for closed swaps.

Requirements:

  • Contract must not be paused
  • Quote token must not be zero address
  • Caller's quote token balance must cover all active buy orders plus this amount, else RestrictedSwap_InsufficientQuoteTokenAmount
  • Caller must have sufficient quote token allowance for this contract (all active buy orders plus this amount)
  • Quote token must not support ERC-1404 interface
  • deadline must be > 0, not in the past, and within maxSwapLifetime
  • minimumFillAmount must be <= restrictedTokenAmount, and must be 0 when restrictedTokenSender is a concrete address (closed swap)
  • If minimumFillAmount is not 0, quoteTokenAmount * minimumFillAmount must be a multiple of restrictedTokenAmount (see Partial Fills), else RestrictedSwap_InvalidMinimumFillAmount
  • For a closed buy order (restrictedTokenSender is a concrete address): pendingBuysOf(caller, restrictedTokenSender) + restrictedTokenAmount must not be more than the restricted token balance of restrictedTokenSender, else RestrictedSwap_PendingBuysExceedBalance. Each buyer has a separate total for each seller.

Emits: SwapConfigured(swapNumber, restrictedTokenSender, restrictedTokenAmount, quoteToken, quoteTokenSender, quoteTokenAmount, deadline, minimumFillAmount)


configureSellWithPermit(uint256 restrictedTokenAmount, address quoteToken, address quoteTokenSender, uint256 quoteTokenAmount, uint256 deadline, uint256 minimumFillAmount, uint256 permitValue, uint256 permitDeadline, uint8 v, bytes32 r, bytes32 s)​

Same as configureSell, but approves the restricted-token allowance via an EIP-2612 permit signature so approve + configure land in a single (optionally relayer-driven) transaction.

Parameters:

  • All parameters of configureSell, plus:
  • permitValue (uint256): The EIP-2612 value that the caller signed. The contract gives it to permit with no change. See The value of permitValue
  • permitDeadline (uint256): EIP-2612 permit deadline (must be >= block.timestamp)
  • v, r, s: Components of the permit signature

Requirements:

  • Same as configureSell
  • The restricted token must implement EIP-2612
  • permitValue must cover requiredAllowance(caller, restrictedToken) + restrictedTokenAmount when the transaction executes (permit replaces the allowance). After the permit, the contract examines the allowance again. If it is not sufficient, the call reverts with RestrictedSwap_InsufficientRestrictedTokenAllowanceAfterPermit

Emits: SwapConfigured(swapNumber, restrictedTokenSender, restrictedTokenAmount, quoteToken, quoteTokenSender, quoteTokenAmount, deadline, minimumFillAmount)


configureBuyWithPermit(uint256 restrictedTokenAmount, address restrictedTokenSender, address quoteToken, uint256 quoteTokenAmount, uint256 deadline, uint256 minimumFillAmount, uint256 permitValue, uint256 permitDeadline, uint8 v, bytes32 r, bytes32 s)​

Same as configureBuy, but approves the quote-token allowance via an EIP-2612 permit signature so approve + configure land in a single (optionally relayer-driven) transaction.

Parameters:

  • All parameters of configureBuy, plus:
  • permitValue (uint256): The EIP-2612 value that the caller signed. The contract gives it to permit with no change. See The value of permitValue
  • permitDeadline (uint256): EIP-2612 permit deadline (must be >= block.timestamp)
  • v, r, s: Components of the permit signature

Requirements:

  • Same as configureBuy
  • The quote token must implement EIP-2612
  • permitValue must cover requiredAllowance(caller, quoteToken) + quoteTokenAmount when the transaction executes (permit replaces the allowance). After the permit, the contract examines the allowance again. If it is not sufficient, the call reverts with RestrictedSwap_InsufficientQuoteTokenAllowanceAfterPermit

Emits: SwapConfigured(swapNumber, restrictedTokenSender, restrictedTokenAmount, quoteToken, quoteTokenSender, quoteTokenAmount, deadline, minimumFillAmount)


Swap Execution Functions​

completeSwapWithQuoteToken(uint256 swapNumber_)​

Completes a swap by providing quote tokens (used by quote token sender in sell-configured swaps).

Parameters:

  • swapNumber_ (uint256): The swap number to complete

Requirements:

  • Contract must not be paused
  • Swap must not be canceled or already completed
  • Caller must be the quote token sender for this swap
  • Swap status must be SellConfigured
  • Quote token sender must have sufficient quote token balance
  • Restricted token sender must have sufficient restricted token balance
  • Transfer restrictions must be satisfied between parties

Emits: SwapComplete(swapNumber, restrictedTokenSender, restrictedTokenAmount, quoteTokenSender, quoteToken, quoteTokenAmount, deadline)


completeSwapWithQuoteTokenPermit(uint256 swapNumber_, uint256 permitValue, uint256 permitDeadline, uint8 v, bytes32 r, bytes32 s)​

Same as completeSwapWithQuoteToken, but approves the quote-token allowance via an EIP-2612 permit signature so approve + complete land in a single transaction.

Parameters:

  • swapNumber_ (uint256): The swap number to complete
  • permitValue (uint256): The EIP-2612 value that the caller signed. The contract gives it to permit with no change. See The value of permitValue
  • permitDeadline (uint256): EIP-2612 permit deadline (must be >= block.timestamp)
  • v, r, s: Components of the permit signature

Requirements:

  • Same as completeSwapWithQuoteToken
  • The quote token must implement EIP-2612
  • permitValue must cover requiredAllowance(caller, quoteToken) + quoteTokenAmount when the transaction executes (permit replaces the allowance). After the permit, the contract examines the allowance again. If it is not sufficient, the call reverts with RestrictedSwap_InsufficientQuoteTokenAllowanceAfterPermit

Emits: SwapComplete(swapNumber, restrictedTokenSender, restrictedTokenAmount, quoteTokenSender, quoteToken, quoteTokenAmount, deadline)


completeSwapWithRestrictedToken(uint256 swapNumber_, uint256 sellSwapNumber_)​

Completes a closed buy order (or an accepted bid) by providing restricted tokens (used by the restricted token sender in buy-configured swaps).

Parameters:

  • swapNumber_ (uint256): The swap number of the bid/closed buy order to complete
  • sellSwapNumber_ (uint256): The swap number of the caller's own open sell offer this settlement draws from, deducting the settled amount from that offer in the same transaction (emitting OrderResized); pass 0 for a standalone settlement that does not draw from an open offer

Requirements:

  • Contract must not be paused
  • Swap must not be canceled or already completed
  • Caller must be the restricted token sender for this swap
  • Swap status must be BuyConfigured
  • Swap must be a closed buy order (open buy orders must be filled via takeOpenBuy, else RestrictedSwap_OpenOrderRequiresTake)
  • Quote token sender must have sufficient quote token balance
  • Restricted token sender must have sufficient restricted token balance
  • Transfer restrictions must be satisfied between parties
  • When sellSwapNumber_ != 0: it must reference an open sell offer owned by the caller, and the settled amount must not exceed that offer's remaining size (RestrictedSwap_ExceedsParentRemaining)

Emits: SwapComplete(swapNumber, restrictedTokenSender, restrictedTokenAmount, quoteTokenSender, quoteToken, quoteTokenAmount, deadline); also OrderResized on the parent offer when sellSwapNumber_ != 0


completeSwapWithRestrictedTokenPermit(uint256 swapNumber_, uint256 sellSwapNumber_, uint256 permitValue, uint256 permitDeadline, uint8 v, bytes32 r, bytes32 s)​

Same as completeSwapWithRestrictedToken, but approves the restricted-token allowance via an EIP-2612 permit signature so approve + settle land in a single transaction.

Parameters:

  • swapNumber_ (uint256): The swap number of the bid/closed buy order to complete
  • sellSwapNumber_ (uint256): The caller's own open sell offer to deduct from, or 0 for a standalone settlement
  • permitValue (uint256): The EIP-2612 value that the caller signed. The contract gives it to permit with no change. See The value of permitValue
  • permitDeadline (uint256): EIP-2612 permit deadline (must be >= block.timestamp)
  • v, r, s: Components of the permit signature

Requirements:

  • Same as completeSwapWithRestrictedToken
  • The restricted token must implement EIP-2612
  • permitValue (permit replaces the allowance): if sellSwapNumber_ == 0, it must cover requiredAllowance(caller, restrictedToken) + restrictedTokenAmount. If a parent offer is named, requiredAllowance(caller, restrictedToken) is sufficient, because the reservation of the parent already covers the bid. The contract uses the values when the transaction executes. After the permit, the contract examines the allowance again. If it is not sufficient, the call reverts with RestrictedSwap_InsufficientRestrictedTokenAllowanceAfterPermit

Emits: SwapComplete(...); also OrderResized on the parent offer when sellSwapNumber_ != 0


takeOpenSell(uint256 swapNumber_, uint256 fillAmount)​

Fills (fully or partially) an open sell order configured with quoteTokenSender == address(0). The caller receives fillAmount restricted tokens and pays the exact pro-rata quoteTokenAmount * fillAmount / restrictedTokenAmount.

Parameters:

  • swapNumber_ (uint256): The open sell order to fill
  • fillAmount (uint256): Amount of restricted tokens to receive

Requirements:

  • Contract must not be paused
  • Swap must not be canceled or already completed
  • Swap must be an open sell order, else RestrictedSwap_NotOpenOrder
  • Caller must not be the order's restrictedTokenSender, else RestrictedSwap_SelfFillNotAllowed
  • fillAmount must be > 0 and <= remainingRestrictedTokenAmount, else RestrictedSwap_InvalidFillAmount
  • fillAmount must be >= minimumFillAmount unless it takes the entire remaining amount, else RestrictedSwap_FillBelowMinimum
  • The pro-rata quote charge must be a whole number, else RestrictedSwap_AmountNotDivisible
  • Caller must have sufficient quote token balance and allowance
  • The seller's restricted token balance must cover fillAmount, else RestrictedSwap_InsufficientRestrictedTokenAmount. The configure-time check does not hold the tokens, so the seller can transfer them later.
  • Transfer restrictions must be satisfied between parties (checked against the actual taker). A fill that the unlocked balance of the seller does not cover reverts with SENDER TOKENS LOCKED.

Emits: OpenSwapFilled(swapNumber, filler, fillRestrictedAmount, fillQuoteAmount, remainingRestrictedAmount); when the fill exhausts the order (remainingRestrictedAmount of 0), also SwapComplete(swapNumber, seller, settledRestricted, address(0), quoteToken, settledQuote, deadline)


takeOpenSellWithPermit(uint256 swapNumber_, uint256 fillAmount, uint256 permitValue, uint256 permitDeadline, uint8 v, bytes32 r, bytes32 s)​

Same as takeOpenSell, but approves the quote-token allowance via an EIP-2612 permit signature.

Parameters:

  • swapNumber_ (uint256): The open sell order to fill
  • fillAmount (uint256): Amount of restricted tokens to receive
  • permitValue (uint256): The EIP-2612 value that the caller signed. The contract gives it to permit with no change. See The value of permitValue
  • permitDeadline (uint256): EIP-2612 permit deadline (must be >= block.timestamp)
  • v, r, s: Components of the permit signature

Requirements:

  • Same as takeOpenSell
  • The quote token must implement EIP-2612
  • permitValue must cover requiredAllowance(caller, quoteToken) + fillQuoteAmount when the transaction executes (permit replaces the allowance). After the permit, the contract examines the allowance again. If it is not sufficient, the call reverts with RestrictedSwap_InsufficientQuoteTokenAllowanceAfterPermit

Emits: OpenSwapFilled(...); when the fill exhausts the order, also SwapComplete(swapNumber, seller, settledRestricted, address(0), quoteToken, settledQuote, deadline)


takeOpenBuy(uint256 swapNumber_, uint256 fillAmount, uint256 sellSwapNumber_)​

Fills (fully or partially) an open buy order configured with restrictedTokenSender == address(0). The caller delivers fillAmount restricted tokens and receives the exact pro-rata quote amount.

Parameters:

  • swapNumber_ (uint256): The open buy order to fill
  • fillAmount (uint256): Amount of restricted tokens to deliver
  • sellSwapNumber_ (uint256): The caller's own open sell offer this delivery draws from, deducting fillAmount from that offer in the same transaction (emitting OrderResized); pass 0 when the fill draws from no open offer

Requirements:

  • Contract must not be paused
  • Swap must not be canceled or already completed
  • Swap must be an open buy order, else RestrictedSwap_NotOpenOrder
  • Caller must not be the order's quoteTokenSender, else RestrictedSwap_SelfFillNotAllowed
  • fillAmount must be > 0 and <= remainingRestrictedTokenAmount, else RestrictedSwap_InvalidFillAmount
  • fillAmount must be >= minimumFillAmount unless it takes the entire remaining amount, else RestrictedSwap_FillBelowMinimum
  • The pro-rata quote credit must be a whole number, else RestrictedSwap_AmountNotDivisible
  • Caller must have sufficient restricted token balance and allowance
  • Transfer restrictions must be satisfied between parties (checked against the actual taker)
  • When sellSwapNumber_ != 0: it must reference an open sell offer owned by the caller, fillAmount must divide cleanly against that offer's price ratio, and must not exceed its remaining size (RestrictedSwap_ExceedsParentRemaining)

Emits: OpenSwapFilled(...); when the fill exhausts the order, also SwapComplete(swapNumber, address(0), settledRestricted, buyer, quoteToken, settledQuote, deadline); also OrderResized on the parent offer when sellSwapNumber_ != 0


takeOpenBuyWithPermit(uint256 swapNumber_, uint256 fillAmount, uint256 sellSwapNumber_, uint256 permitValue, uint256 permitDeadline, uint8 v, bytes32 r, bytes32 s)​

Same as takeOpenBuy, but approves the restricted-token allowance via an EIP-2612 permit signature.

Parameters:

  • swapNumber_ (uint256): The open buy order to fill
  • fillAmount (uint256): Amount of restricted tokens to deliver
  • sellSwapNumber_ (uint256): The caller's own open sell offer to deduct from, or 0
  • permitValue (uint256): The EIP-2612 value that the caller signed. The contract gives it to permit with no change. See The value of permitValue
  • permitDeadline (uint256): EIP-2612 permit deadline (must be >= block.timestamp)
  • v, r, s: Components of the permit signature

Requirements:

  • Same as takeOpenBuy
  • The restricted token must implement EIP-2612
  • permitValue (permit replaces the allowance): if sellSwapNumber_ == 0, sign requiredAllowance(caller, restrictedToken) + fillAmount. If a parent offer is named, requiredAllowance(caller, restrictedToken) is sufficient. The contract uses the values when the transaction executes. After the permit, the contract examines the allowance again. If it is not sufficient, the call reverts with RestrictedSwap_InsufficientRestrictedTokenAllowanceAfterPermit

Emits: OpenSwapFilled(...); when the fill exhausts the order, also SwapComplete(swapNumber, address(0), settledRestricted, buyer, quoteToken, settledQuote, deadline); also OrderResized on the parent offer when sellSwapNumber_ != 0


cancelSwap(uint256 swapNumber_)​

Cancels a configured swap. Before the deadline, the creator can cancel. For a closed buy order, the named seller (the restrictedTokenSender) can cancel too. A buyer can name a seller without the seller's consent, so the seller must be able to end the order at any time. After the deadline, anyone can cancel.

The cancel releases the creator's reservations for the remaining amounts. For a closed buy order, it also releases the remaining amount from pendingBuys and pendingBuysOf.

Parameters:

  • swapNumber_ (uint256): The swap number to cancel

Requirements:

  • Swap must not be canceled or already completed
  • Swap must be properly configured
  • For non-expired swaps:
    • For SellConfigured swaps: caller must be the restricted token sender
    • For BuyConfigured swaps: caller must be the quote token sender or, for a closed buy order, the named restricted token sender
  • For expired swaps: anyone can cancel

Emits: SwapCanceled(sender, swapNumber)


Order Management Functions​

decreaseOrder(uint256 swapNumber, uint256 newRemainingRestrictedAmount)​

Shrinks an active open order's remaining size in place (owner-only, decrease-only) — the single-signature alternative to cancel-and-recreate. The paired quote amount shrinks exactly pro-rata on the order's original price. Shrinking to 0 cancels the order. Like cancelSwap, callable while paused and on expired orders (exit-type action).

Parameters:

  • swapNumber (uint256): The caller's open order
  • newRemainingRestrictedAmount (uint256): New remaining restricted-token size; must be strictly less than the current remaining amount (0 cancels the order)

Requirements:

  • Caller must be the order's creator, else RestrictedSwap_InvalidOrderOwner
  • Swap must be an open order, else RestrictedSwap_NotOpenOrder
  • New size must be strictly smaller than the current remaining amount, else RestrictedSwap_InvalidResizeAmount
  • The new quote remainder must be a whole number at the original price ratio, else RestrictedSwap_AmountNotDivisible

Emits: OrderResized(swapNumber, newRemainingRestrictedAmount, newRemainingQuoteAmount); also SwapCanceled(...) when shrunk to zero


increaseOrder(uint256 swapNumber, uint256 newRemainingRestrictedAmount)​

Grows an active open order's remaining size in place (owner-only, increase-only). Because growing creates new exposure, this carries configure-grade guards: blocked while paused, blocked on expired orders, and the creator's balance and allowance must already cover all reservations plus the growth. After an increase the remaining size may exceed the originally configured amount. The contract records the filled amount. The SwapComplete event of the order and settledRestrictedTokenAmount report the settled total, not the configured amount.

Parameters:

  • swapNumber (uint256): The caller's open order
  • newRemainingRestrictedAmount (uint256): New remaining restricted-token size; must be strictly greater than the current remaining amount

Requirements:

  • Caller must be the order's creator, else RestrictedSwap_InvalidOrderOwner
  • Contract must not be paused; order must not be expired
  • Swap must be an open order, else RestrictedSwap_NotOpenOrder
  • New size must be strictly greater than the current remaining amount, else RestrictedSwap_InvalidResizeAmount
  • The added amount must divide cleanly against the order's original price ratio, else RestrictedSwap_AmountNotDivisible
  • The creator's balance and allowance must cover all reservations plus the growth. For a sell, this is the restricted token (RestrictedSwap_InsufficientRestrictedTokenAmount, RestrictedSwap_InsufficientRestrictedTokenAllowance). For a buy, this is the quote token (RestrictedSwap_InsufficientQuoteTokenAmount, RestrictedSwap_InsufficientQuoteTokenAllowance).

Emits: OrderResized(swapNumber, newRemainingRestrictedAmount, newRemainingQuoteAmount)


increaseOrderWithPermit(uint256 swapNumber, uint256 newRemainingRestrictedAmount, uint256 permitValue, uint256 permitDeadline, uint8 v, bytes32 r, bytes32 s)​

Same as increaseOrder, but tops up the allowance via an EIP-2612 permit signature so the top-up and the size increase land atomically. The permitted token is the restricted token for an open sell, or the order's quote token for an open buy.

Parameters:

  • swapNumber (uint256): The caller's open order
  • newRemainingRestrictedAmount (uint256): New remaining restricted-token size (strictly greater than current)
  • permitValue (uint256): The EIP-2612 value that the caller signed. The contract gives it to permit with no change. See The value of permitValue
  • permitDeadline (uint256): EIP-2612 permit deadline (must be >= block.timestamp)
  • v, r, s: Components of the permit signature

Requirements:

  • Same as increaseOrder
  • The permitted token must implement EIP-2612
  • permitValue must cover requiredAllowance + added (open sell, restricted token) or requiredAllowance + quoteAdded (open buy, quote token) when the transaction executes, because permit replaces the allowance. The function uses the permit of one side only. Thus one signed value is sufficient

Emits: OrderResized(swapNumber, newRemainingRestrictedAmount, newRemainingQuoteAmount)


Query Functions​

swapNumber() → uint256​

Returns the current swap number counter.

Returns:

  • uint256: The current swap number (total swaps configured)

swapStatus(uint256 swapNumber_) → SwapStatus​

Returns the status of a specific swap.

Parameters:

  • swapNumber_ (uint256): The swap number to query

Returns:

  • SwapStatus: The status enum (SellConfigured=1, BuyConfigured=2, Complete=3, Canceled=4)

Requirements:

  • Swap record must exist

remainingRestrictedTokenAmount(uint256 swapNumber_) → uint256​

Returns the restricted-token amount that was never filled on a swap. Only open orders decrement it (each partial fill, plus decreaseOrder / increaseOrder resizes); a closed swap settles its original amounts in full, so it reports its configure-time amount for its whole lifetime.

Terminal states:

  • Complete → always 0.
  • Canceled → retains the amount withdrawn unfilled, deliberately kept as on-chain history of what was pulled back rather than traded (the refund itself is visible in pendingSells / requiredAllowance dropping). The one exception is an order retired by shrinking to zero — via decreaseOrder(swapNumber, 0) or a parent-offer deduction — where the shrink already consumed the remainder, so it reports 0.

Read swapStatus(swapNumber) alongside this getter: a non-zero value on a terminal record is history, not available inventory.

Parameters:

  • swapNumber_ (uint256): The swap number to query

Returns:

  • uint256: The unfilled restricted-token amount

settledRestrictedTokenAmount(uint256 swapNumber_) → uint256​

Returns the restricted-token amount that the fills of a swap transferred. An open order reports the sum of its OpenSwapFilled amounts, also after a cancel. A resize does not change the value. On completion of an open order, the value is the restrictedTokenAmount of the SwapComplete event. A closed swap reports 0 before completion and its configured amount after completion.

Terminal states:

  • Complete open order → the settled total of its SwapComplete event.
  • Canceled open order → the amount filled before the cancel. This holds also after a shrink to zero.
  • Closed swap → 0 before completion, restrictedTokenAmount after completion, 0 after a cancel.

Parameters:

  • swapNumber_ (uint256): The swap number to query

Returns:

  • uint256: The settled restricted-token amount

Requirements:

  • Swap record must exist, else RestrictedSwap_InvalidSwapRecord

minimumFillAmount(uint256 swapNumber_) → uint256​

Returns the minimum restricted-token amount a taker must fill on an open order (unless taking the entire remaining amount).

Parameters:

  • swapNumber_ (uint256): The swap number to query

Returns:

  • uint256: The configured minimum fill amount (0 means no minimum)

isOpenOrder(uint256 swapNumber_) → bool​

Returns whether a swap is an open order (one zero counterparty) that must be filled via takeOpenSell / takeOpenBuy.

Parameters:

  • swapNumber_ (uint256): The swap number to query

Returns:

  • bool: True if the swap is an open order

maxSwapLifetime() → uint256​

Returns the maximum allowed distance between block.timestamp and a swap's deadline at configure time, fixed at deployment.

Returns:

  • uint256: The maximum swap lifetime in seconds

MIN_SWAP_LIFETIME_LIMIT() → uint256​

Returns the compile-time floor that maxSwapLifetime must not fall below at deployment.

Returns:

  • uint256: The minimum allowed value for maxSwapLifetime

MAX_SWAP_LIFETIME_LIMIT() → uint256​

Returns the compile-time ceiling that maxSwapLifetime must not exceed at deployment.

Returns:

  • uint256: The maximum allowed value for maxSwapLifetime

requiredAllowance(address addr, address token) → uint256​

Returns the sum of the active reservations of a maker in a token. The ledger is advisory: the maker keeps control of the real allowance and balance. See "The Reservation Ledger Is Advisory".

Parameters:

  • addr (address): Maker address
  • token (address): Token address

Returns:

  • uint256: Reserved amount of the maker in the token

makerCoverage(address maker, address token) → (uint256 reserved, uint256 allowance, uint256 balance)​

Returns the reservation of a maker next to the real allowance to the swap contract and the real balance.

Parameters:

  • maker (address): Maker address
  • token (address): Token address; the restricted token for a seller, the quote token for a buyer

Returns:

  • reserved (uint256): Sum of the active reservations of the maker in the token
  • allowance (uint256): Real allowance of the maker to the swap contract in the token
  • balance (uint256): Real balance of the maker in the token

isFillable(uint256 swapNumber) → bool​

Returns true when each named party of an active order covers its remaining leg with its real allowance to the swap contract and its real balance. An open order names only the maker. A complete, canceled or expired order is not fillable.

Parameters:

  • swapNumber (uint256): The swap number to query

Returns:

  • bool: True when the order can settle in full at this moment

Requirements:

  • Swap record must exist

calculateCounterpartyAllowance(address addr, address token, uint256 pageNumber, uint256 pageSize) → uint256​

Returns the remaining amount that addr must deliver as the named counterparty of active closed swaps, summed over one page of swap numbers. Informational only; the contract records no reservation for a counterparty.

Parameters:

  • addr (address): Counterparty address
  • token (address): Token address
  • pageNumber (uint256): Page number (0-based)
  • pageSize (uint256): Number of swaps per page

Returns:

  • uint256: Remaining counterparty amount for the page

pendingBuys(address addr) → uint256​

Returns the restricted token amount that all buyers request from a seller across their active closed buy orders. An open buy order does not count, because it has no named seller. Index the OpenSwapFilled events for the deliveries of open buy orders.

Each buyer can request at most the seller's balance (see pendingBuysOf), but several buyers can each do so. Thus this value can be more than the seller's balance. The seller did not consent to these orders and can cancel each of them with cancelSwap.

Parameters:

  • addr (address): Seller address (the named restrictedTokenSender of a closed buy order)

Returns:

  • uint256: Restricted token amount that all buyers request from the seller

pendingBuysOf(address buyer, address seller) → uint256​

Returns the restricted token amount that one buyer requests from one seller across the active closed buy orders of that buyer. configureBuy and configureBuyWithPermit revert with RestrictedSwap_PendingBuysExceedBalance if a new closed buy order makes this value more than the seller's balance.

The contract checks the cap only at configure time. If the seller transfers tokens later, this value can be more than the seller's balance. An expired order counts until someone cancels it.

Parameters:

  • buyer (address): Buyer address (the quoteTokenSender of the closed buy orders)
  • seller (address): Seller address (the named restrictedTokenSender)

Returns:

  • uint256: Restricted token amount that the buyer requests from the seller

pendingSells(address addr) → uint256​

Returns pending restricted tokens to sell for an address. The value covers the closed and the open sell orders of addr. It decreases on a fill, on a completion, on a cancel and on decreaseOrder. An expired order counts until someone cancels it. At configure time and at an increase, the balance of addr must cover this value plus the new amount. The contract checks the balance only then, so the value can be more than the balance after a later transfer.

Parameters:

  • addr (address): Seller address

Returns:

  • uint256: Amount of pending restricted tokens to sell

restrictedLockupToken() → address​

Returns the RestrictedLockupToken contract address.

Returns:

  • address: The RestrictedLockupToken contract address

accessControl() → address​

Returns the AccessControl contract address.

Returns:

  • address: The AccessControl contract address

INTERFACE_ID() → bytes4​

Returns the interface ID for ERC-165 support.

Returns:

  • bytes4: The interface identifier

isSwapExpired(uint256 swapNumber_) → bool​

Checks if a specific swap has expired based on its deadline.

Parameters:

  • swapNumber_ (uint256): The swap number to check

Returns:

  • bool: True if the swap has expired, false otherwise

Requirements:

  • Swap record must exist

Note:

  • A swap is considered expired if it has a deadline > 0 and the current block timestamp is greater than the deadline
  • Configured swaps always carry a deadline > 0 (the 0 sentinel is rejected at configure time)

Inherited Functions​

Pausable Functions​

paused() → bool​

Returns whether the contract is currently paused.

Returns:

  • bool: True if paused, false otherwise

ERC-2771 Functions​

isTrustedForwarder(address forwarder) → bool​

Checks if an address is a trusted forwarder for meta-transactions.

Parameters:

  • forwarder (address): Address to check

Returns:

  • bool: True if the address is a trusted forwarder

trustedForwarder() → address​

Returns the trusted forwarder address.

Returns:

  • address: The trusted forwarder address

ERC-165 Functions​

supportsInterface(bytes4 interfaceId) → bool​

Checks if the contract supports a specific interface.

Parameters:

  • interfaceId (bytes4): Interface identifier to check

Returns:

  • bool: True if the interface is supported

Events​

SwapConfigured(uint256 indexed swapNumber, address indexed restrictedTokenSender, uint256 restrictedTokenAmount, address quoteToken, address indexed quoteTokenSender, uint256 quoteTokenAmount, uint256 deadline, uint256 minimumFillAmount)​

Emitted when a new swap is configured. An open sell order carries quoteTokenSender == address(0); an open buy order carries restrictedTokenSender == address(0).

Parameters:

  • swapNumber (uint256, indexed): Unique swap identifier
  • restrictedTokenSender (address, indexed): Address providing restricted tokens (address(0) for an open buy order)
  • restrictedTokenAmount (uint256): Amount of restricted tokens in the swap
  • quoteToken (address): Quote token contract address
  • quoteTokenSender (address, indexed): Address providing quote tokens (address(0) for an open sell order)
  • quoteTokenAmount (uint256): Amount of quote tokens in the swap
  • deadline (uint256): Unix timestamp deadline for swap expiration
  • minimumFillAmount (uint256): Minimum restricted-token amount a taker must fill on an open order (unless taking the entire remaining amount); 0 means no minimum

SwapComplete(uint256 indexed swapNumber, address indexed restrictedTokenSender, uint256 restrictedTokenAmount, address indexed quoteTokenSender, address quoteToken, uint256 quoteTokenAmount, uint256 deadline)​

Emitted when a swap completes. For a closed swap, the amounts are the configured amounts, which the swap transfers in full. For an open order, the last fill emits it with the settled totals. These are the sum of the fills and its quote at the configured price. A parent-offer deduction is a resize, not a fill, and the child swap reports its tokens. The open side is address(0), as in SwapConfigured. Read the takers from the OpenSwapFilled events.

Parameters:

  • swapNumber (uint256, indexed): Unique swap identifier
  • restrictedTokenSender (address, indexed): Address that provided restricted tokens; address(0) for an open buy order
  • restrictedTokenAmount (uint256): Settled amount of restricted tokens. For a closed swap, this is the configured amount
  • quoteTokenSender (address, indexed): Address that provided quote tokens; address(0) for an open sell order
  • quoteToken (address): Quote token contract address
  • quoteTokenAmount (uint256): Settled amount of quote tokens. For a closed swap, this is the configured amount
  • deadline (uint256): Unix timestamp deadline for swap expiration

SwapCanceled(address indexed sender, uint256 indexed swapNumber)​

Emitted when a swap is canceled.

Parameters:

  • sender (address, indexed): Address that canceled the swap
  • swapNumber (uint256, indexed): Unique swap identifier

OpenSwapFilled(uint256 indexed swapNumber, address indexed filler, uint256 fillRestrictedAmount, uint256 fillQuoteAmount, uint256 remainingRestrictedAmount)​

Emitted on every partial or final fill of an open order via takeOpenSell / takeOpenBuy. A remainingRestrictedAmount of 0 indicates the order is now fully filled and its status is Complete. SwapComplete follows in the same transaction with the settled totals. The sum of the fills of an order is equal to these totals, and each filler is a counterparty.

Parameters:

  • swapNumber (uint256, indexed): Unique swap identifier
  • filler (address, indexed): Address that took this fill (the actual counterparty for this slice)
  • fillRestrictedAmount (uint256): Restricted-token amount transferred in this fill
  • fillQuoteAmount (uint256): Quote-token amount transferred in this fill
  • remainingRestrictedAmount (uint256): Restricted-token amount still unfilled after this event

OrderResized(uint256 indexed swapNumber, uint256 newRemainingRestrictedAmount, uint256 newRemainingQuoteAmount)​

Emitted when an open order's remaining size changes without a fill — the owner called decreaseOrder / increaseOrder / increaseOrderWithPermit, or a linked settlement deducted from a parent offer (completeSwapWithRestrictedToken / takeOpenBuy with a sellSwapNumber). The size can both shrink and grow (possibly above the originally configured amount). If a shrink reaches zero, SwapCanceled is emitted in the same transaction and the order is terminal.

Parameters:

  • swapNumber (uint256, indexed): Unique swap identifier of the resized order
  • newRemainingRestrictedAmount (uint256): Restricted-token amount still offered after the resize
  • newRemainingQuoteAmount (uint256): Quote-token amount still expected after the resize

Inherited Events​

Paused(address account)​

Emitted when the contract is paused.

Parameters:

  • account (address): Address that paused the contract

Unpaused(address account)​

Emitted when the contract is unpaused.

Parameters:

  • account (address): Address that unpaused the contract

Custom Errors​

Configuration Errors​

RestrictedSwap_InvalidAccessControl()​

Thrown when an invalid access control address is provided during construction.


RestrictedSwap_InvalidRestrictedLockupToken()​

Thrown when a zero address is provided as the RestrictedLockupToken during construction.


RestrictedSwap_InvalidTrustedForwarder()​

Thrown when a zero address is provided as the trusted forwarder during construction.


RestrictedSwap_InvalidMaxSwapLifetime()​

Thrown when the constructor's maxSwapLifetime_ is outside [MIN_SWAP_LIFETIME_LIMIT, MAX_SWAP_LIFETIME_LIMIT].


RestrictedSwap_InvalidQuoteToken()​

Thrown when a zero address is provided as the quote token.


RestrictedSwap_InvalidQuoteTokenSender()​

Thrown when a zero address is provided as the quote token sender.


RestrictedSwap_InvalidRestrictedTokenSender()​

Thrown when a zero address is provided as the restricted token sender.


RestrictedSwap_InvalidRestrictedTokenAmount()​

Thrown when zero is provided as the restricted token amount.


RestrictedSwap_InvalidQuoteTokenAmount()​

Thrown when zero is provided as the quote token amount.


Validation Errors​

RestrictedSwap_QuoteTokenMustNotSupportIERC1404()​

Thrown when the quote token supports ERC-1404 interface (restricted tokens not allowed as quote tokens).


RestrictedSwap_InsufficientRestrictedTokenAllowance()​

Thrown at configure and increase time when the restricted-token allowance of the creator does not cover all reservations, and at settlement time when the real restricted-token allowance of a party does not cover its leg. The settlement check runs before any transfer.


RestrictedSwap_InsufficientQuoteTokenAllowance()​

Thrown at configure and increase time when the quote-token allowance of the creator does not cover all reservations, and at settlement time when the real quote-token allowance of a party does not cover its leg. The settlement check runs before any transfer.


RestrictedSwap_InsufficientRestrictedTokenAmount()​

Thrown when the restricted token balance of the sender does not cover the required amount. At configureSell, configureSellWithPermit, increaseOrder and increaseOrderWithPermit, the balance must cover all active sell orders (pendingSells) plus the new amount. An expired order counts until someone cancels it. At a fill or a completion, the balance must cover the amount of the fill or of the swap.


RestrictedSwap_InsufficientQuoteTokenAmount()​

Thrown when the quote token balance is insufficient for the swap.


RestrictedSwap_InsufficientRestrictedTokenAllowanceAfterPermit()​

Thrown by a ...WithPermit function when the restricted-token allowance is not sufficient after the permit. For example, permitValue is less than the requirement when the transaction executes, or the signature is not valid.


RestrictedSwap_InsufficientQuoteTokenAllowanceAfterPermit()​

Thrown by a ...WithPermit function when the quote-token allowance is not sufficient after the permit. For example, permitValue is less than the requirement when the transaction executes, or the signature is not valid.


RestrictedSwap_PendingBuysExceedBalance()​

Thrown by configureBuy and configureBuyWithPermit for a closed buy order. The buyer's total for the named seller (pendingBuysOf) plus the new amount is more than the seller's balance. An expired order counts until someone cancels it.


RestrictedSwap_DeadlineRequired()​

Thrown at configure time when deadline is 0 (the "no deadline" sentinel is no longer accepted).


RestrictedSwap_DeadlineExceedsMaxLifetime()​

Thrown at configure time when deadline - block.timestamp exceeds the contract's maxSwapLifetime.


Swap State Errors​

RestrictedSwap_AlreadyCanceled()​

Thrown when attempting to operate on a swap that has already been canceled.


RestrictedSwap_AlreadyCompleted()​

Thrown when attempting to operate on a swap that has already been completed.


RestrictedSwap_InvalidSwapStatus()​

Thrown when the swap status doesn't match the required status for the operation.


RestrictedSwap_InvalidSwapRecord()​

Thrown when attempting to query a swap that doesn't exist.


RestrictedSwap_SwapExpired()​

Thrown when attempting to complete a swap that has expired based on its deadline.


RestrictedSwap_SwapNotConfigured()​

Thrown when attempting to cancel a swap that hasn't been properly configured.


Authorization Errors​

RestrictedSwap_InvalidTokenSender()​

Thrown when the caller is not authorized to complete the swap (not the expected token sender).


RestrictedSwap_InvalidCanceler()​

Thrown when the caller is not authorized to cancel the swap via cancelSwap. Before the deadline, the creator can cancel a live order, and the named seller can cancel a closed buy order. Anyone can cancel an expired order. Owner checks on the resize paths use RestrictedSwap_InvalidOrderOwner instead.


RestrictedSwap_InvalidOrderOwner()​

Thrown when decreaseOrder / increaseOrder is called by someone other than the order's creator.


Open Order & Resize Errors​

RestrictedSwap_NotOpenOrder()​

Thrown when an open-order-only operation (takeOpenSell / takeOpenBuy / decreaseOrder / increaseOrder) targets a closed swap (both counterparties named).


RestrictedSwap_OpenOrderRequiresTake()​

Thrown when completeSwapWithQuoteToken / completeSwapWithRestrictedToken (or their permit variants) target an open order, which must instead be filled via takeOpenSell / takeOpenBuy.


RestrictedSwap_SelfFillNotAllowed()​

Thrown when the configurer of an open order attempts to fill it themselves (takeOpenSell by the order's restrictedTokenSender, or takeOpenBuy by its quoteTokenSender).


RestrictedSwap_InvalidFillAmount()​

Thrown when a takeOpenSell / takeOpenBuy fill amount is zero or exceeds the order's remaining size.


RestrictedSwap_FillBelowMinimum()​

Thrown when a take fill is below the order's minimumFillAmount and does not take the entire remaining amount (a below-minimum tail can always be taken in full).


RestrictedSwap_InvalidMinimumFillAmount()​

Thrown at configure time when minimumFillAmount exceeds restrictedTokenAmount, or is non-zero on a closed swap (both counterparties named — closed swaps settle in full and never consult the minimum). Also thrown when a non-zero minimumFillAmount is not a valid fill: its quote at the configured price is not a whole number.


RestrictedSwap_AmountNotDivisible()​

Thrown when a fill, resize, or linked parent deduction amount does not produce an integer quote amount at the order's original price ratio (strict exact-pricing rule).


RestrictedSwap_InvalidResizeAmount()​

Thrown when decreaseOrder is given a size that is not strictly smaller, or increaseOrder a size that is not strictly larger, than the order's current remaining amount.


RestrictedSwap_ExceedsParentRemaining()​

Thrown when a linked settle or fill (sellSwapNumber named) would deduct more than the parent offer's remaining size — e.g. a third party filled the parent between signing and execution. Callers should retry with sellSwapNumber = 0 and resize the listing separately.


Transfer Errors​

RestrictedSwap_InconsistentQuoteTokenAmount()​

Thrown when the actual quote token transfer amount doesn't match the expected amount.


RestrictedSwap_InconsistentRestrictedTokenAmount()​

Thrown when the actual restricted token transfer amount doesn't match the expected amount.


Inherited Errors​

EasyAccessControl_DoesNotHaveContractOrTransferAdminRole(address addr)​

Thrown when an address lacks both CONTRACT_ADMIN_ROLE and TRANSFER_ADMIN_ROLE.

Parameters:

  • addr (address): The unauthorized address

EnforcedPause()​

Thrown when an operation is attempted while the contract is paused.


ExpectedPause()​

Thrown when attempting to pause an already paused contract or unpause an unpaused contract.


ReentrancyGuardReentrantCall()​

Thrown when a reentrant call is detected.


SafeERC20FailedOperation(address token)​

Thrown when an ERC-20 operation fails.

Parameters:

  • token (address): The token contract address where the operation failed