The GluexRouter smart contract (version 1.1) represents an optimized iteration of our routing infrastructure. It provides enhanced functionality for highly efficient token routing, dynamic fee collection and the precise execution of onchain interactions through a refined, structured interface. This version introduces advanced mechanisms for surplus and slippage sharing

Deployment

The GluexRouter-v1.1 contract is deployed at the following address on the supported chains by GlueX: Contract Address: 0xe95F6EAeaE1E4d650576Af600b33D9F7e5f9f7fd

Functions

Swap

Executes a token routing operation through an external IExecutor contract using a predefined set of interactions Function Signature
function swap(
    IExecutor executor,
    RouteDescription calldata desc,
    Interaction[] calldata interactions
) external payable returns (uint256 finalOutputAmount);
Parameters
  • executor (IExecutor): The executor contract responsible for processing interactions
  • desc (RouteDescription calldata): A structured object containing input/output token information, fees, limits and recipient addresses
  • interactions (Interaction[] calldata): An array of interaction steps to be executed by the executor
Returns
  • finalOutputAmount (uint256): The final amount of output token received by the outputReceiver after fees and surplus/slippage sharing
Reverts
  • InvalidNativeTokenInputAmount: If the ETH value sent does not match the expected input amount
  • RoutingFeeTooHigh: If desc.routingFee exceeds the maximum allowed fee (_MAX_FEE)
  • RoutingFeeTooLow: If desc.routingFee is below the minimum required fee (_MIN_FEE)
  • PartnerSurplusShareTooHigh: If desc.partnerSurplusShare exceeds _MAX_PARTNER_SURPLUS_SHARE_LIMIT
  • ProtocolSurplusShareTooLow: If desc.protocolSurplusShare is below _MIN_PROTOCOL_SURPLUS_SHARE_LIMIT
  • PartnerSlippageShareTooHigh: If desc.partnerSlippageShare exceeds _MAX_PARTNER_SLIPPAGE_SHARE_LIMIT
  • ProtocolSlippageShareTooLow: If desc.protocolSlippageShare is below _MIN_PROTOCOL_SLIPPAGE_SHARE_LIMIT
  • ZeroAddress: If any required address (eg: inputReceiver, outputReceiver) is a zero address
  • InvalidSlippage: If desc.minOutputAmount is zero
  • SlippageLimitTooLarge: If desc.minOutputAmount exceeds desc.outputAmount
  • InsufficientBalance: If the router does not hold sufficient balance for the intended transfer
  • NativeTransferFailed: If the native token transfer fails

Events

Routed

Emitted upon successful completion of a routing operation Event Signature
event Routed(
    bytes32 indexed uniquePID,
    address indexed userAddress,
    address outputReceiver,
    IERC20 inputToken,
    uint256 inputAmount,
    IERC20 outputToken,
    uint256 finalOutputAmount,
    uint256 partnerFee,
    uint256 routingFee,
    uint256 partnerShare,
    uint256 protocolShare
);
Parameters
  • uniquePID (bytes): The unique identifier for the partner
  • userAddress (address): The address of the user who initiated the route
  • outputReceiver (address): The address of the receiver of the output token
  • inputToken (IERC20): The ERC20 token used as input
  • inputAmount (uint256): The amount of input token used for routing
  • outputToken (IERC20): The ERC20 token received as output
  • finalOutputAmount (uint256): The actual output amount received after routing
  • partnerFee (uint256): The fee charged for the partner
  • routingFee (uint256): The fee charged for the routing operation
  • partnerShare (uint256): The share of surplus/slippage allocated to the partner
  • protocolShare (uint256): The share of surplus/slippage allocated to the protocol