Rubicon Gladius
Contracts Source Code (opens in a new tab)
Overview
Rubicon Gladius is an intent-based trading system that relies on the offchain intents pool what provides a gasless market-making and trading experience while remaining non-custodial with onchain settlement.
PartialFillLib
The main library that implements partial execution of an order and contains GladiusOrder
struct - which, essentially, is an ExclusiveDutchOrder
with an additional fillThreshold
parameter, that allows swappers to set a minimum threshold for a partial fill execution.
struct GladiusOrder {
// Generic order information.
OrderInfo info;
// The time at which the 'DutchOutputs' start decaying.
uint256 decayStartTime;
// The time at which price becomes static.
uint256 decayEndTime;
// The address who has exclusive rights to the order until 'decayStartTime'.
address exclusiveFiller;
// The amount in bps that a non-exclusive filler needs to improve the outputs by to be able to fill the order.
uint256 exclusivityOverrideBps;
// The tokens that the swapper will provide when settling the order.
DutchInput input;
// The tokens that must be received to satisfy the order.
DutchOutput[] outputs;
// Minimum amount of input token, that can be partially filled by taker.
uint256 fillThreshold;
}
partition
function is executed during order’s resolution, it mutates input and output amounts by replacing input amount with quantity
and calculating output amount, based on the initial exchange rate.
function partition(
uint256 quantity,
InputToken memory input,
OutputToken[] memory output,
uint256 fillThreshold
) internal pure returns (InputToken memory, OutputToken[] memory) {
...
uint256 outPart = quantity.mulDivUp(output[0].amount, input.amount);
...
// Mutate amounts in structs.
input.amount = quantity;
output[0].amount = outPart;
BaseGladiusReactor
Base reactor logic for settling orders signed off chain, using arbitrary fill methods specified by fillers. BaseGladiuReactor
implements 8 execute*
entry-points, capturing an execution flow of these functions and leaving implementation of resolve
and transferInputTokens
functions to higher-level reactors.
There are 2 variations of the execute*
entry point, with the first one representing the basic execute
and the second one overloading it with the additional quantity
parameter, which allows fillers
to execute orders partially (as long as fillThreshold
allows it as well).
/// @dev Only full execution of an 'order'
function execute(SignedOrder calldata order) external;
function executeWithCallback(SignedOrder calldata order, bytes calldata callbackData) external;
function executeBatch(SignedOrder[] calldata orders) external;
function executeBatchWithCallback(SignedOrder[] calldata orders, bytes calldata callbackData) external;
/// @dev Either full or partiall execution of an 'order'
function execute(SignedOrder calldata order, uint256 quantity) external;
function executeWithCallback(SignedOrder calldata order, uint256 quantity, bytes calldata callbackData) external;
function executeBatch(SignedOrder[] calldata orders, uint256[] calldata quantities) external;
function executeBatchWithCallback(SignedOrder[] calldata orders, uint256[] calldata quantities, bytes calldata callbackData) external;
GladiusReactor
Inherits BaseGladiusReactor
and implements resolve
(x2) and transferInputTokens
functions. GladiusReactor
resolves an ABI-encoded GladiusOrder
into generic ResolvedOrder
applying decay
and partition
functions alongside. Basically, it treats incoming order as an ExclusiveDutchOrder
, that can be executed not only fully, but also partially.
RubiconFeeController
Applies a fee on each order executed through GladiusReactor
. RubiconFeeController
has 2 types of fees - base fee, that is applied on each pair by default, and a pair-based fee, that will be used for a specific pair replacing the base fee, once enabled.