Skip to content

DEX Contract Interface

The DEX contract (CrocSwapDex) is the main entrypoint for interacting with BEX. It acts as a proxy to the various sidecar contracts that implement the different functionalities.

The contract is deployed on bArtio Testnet at: 0xAB827b1Cc3535A9e549EE387A6E9C3F02F481B49

The CrocSwapDex ABI exposes six Solidity methods:

swap

solidity
function swap(
    address base,
    address quote,
    uint256 poolIdx,
    bool isBuy,
    bool inBaseQty,
    uint128 qty,
    uint16 tip,
    uint128 limitPrice,
    uint128 minOut,
    uint8 reserveFlags
) public payable returns (int128 baseQuote, int128 quoteFlow)

The primary "vanilla" Solidity method that accepts standard argument types. Because swaps are the most common operation, this method runs purely in the "hot-path" without any calls to proxy sidecar contracts.

Parameters

NameTypeDescription
baseaddressThe base token in the swap pair.
quoteaddressThe quote token in the swap pair.
poolIdxuint256The index of the pool to swap in.
isBuyboolTrue if the user wants to pay base token and receive quote token. False if the user wants to receive base token and pay quote token.
inBaseQtyboolIf true, the qty parameter is denominated in base tokens. If false, it's denominated in quote tokens.
qtyuint128The quantity of tokens to swap.
tipuint16The tip amount for the relayer executing the swap.
limitPriceuint128Represents the worse possible price the user is willing to accept. If buying this represents an upper bound.
minOutuint128The minimum amount of output tokens the user is willing to receive.
reserveFlagsuint8Flags indicating whether to use the user's surplus collateral balance for the base and/or quote token.

Returns

NameTypeDescription
baseQuoteint128The net flow of base tokens. Negative if paid from the pool to the user, positive if the opposite.
quoteFlowint128The net flow of quote tokens. Negative if paid from the pool to the user, positive if the opposite.

userCmd

solidity
function userCmd(
    uint16 callpath,
    bytes cmd
) public payable returns (bytes)

Single point of entry for all possible user commands. Accepts a callpath index which maps to the specific proxy sidecar contract and an arbitrary byte string which is specifically structured for that specific sidecar.

Parameters

NameTypeDescription
callpathuint16The callpath index that maps to the specific proxy sidecar contract.
cmdbytesThe arbitrary byte string containing the command data, structured specifically for the corresponding sidecar.

Returns

TypeDescription
bytesThe output data returned by the executed command.

userCmdRelayer

solidity
function userCmdRelayer(
    uint16 callpath,
    bytes cmd,
    bytes conds,
    bytes relayerTip,
    bytes signature
) public payable returns (bytes output)

Identical to userCmd() but executes a command signed by a user off-chain using the EIP-712 standard.

Parameters

NameTypeDescription
callpathuint16The callpath index that maps to the specific proxy sidecar contract.
cmdbytesThe arbitrary byte string containing the command data, structured specifically for the corresponding sidecar.
condsbytesThe conditions for executing the relayed command.
relayerTipbytesThe tip for the relayer executing the command.
signaturebytesThe EIP-712 signature of the user authorizing the relayed command.

Returns

NameTypeDescription
outputbytesThe output data returned by the executed command.

userCmdRouter

solidity
function userCmdRouter(
    uint16 callpath,
    bytes cmd,
    address client
) public payable returns (bytes)

Identical to userCmd() but called by an external router contract on behalf of an end user. The user must have previously approved the router contract.

Parameters

NameTypeDescription
callpathuint16The callpath index that maps to the specific proxy sidecar contract.
cmdbytesThe arbitrary byte string containing the command data, structured specifically for the corresponding sidecar.
clientaddressThe address of the end user on whose behalf the router is executing the command.

Returns

TypeDescription
bytesThe output data returned by the executed command.

protocolCmd

solidity
function protocolCmd(
    uint16 callpath,
    bytes cmd,
    bool sudo
) public payable

Executes a protocol administrative command. This call can only be made by the protocol authority contract.

Parameters

NameTypeDescription
callpathuint16The callpath index that maps to the specific proxy sidecar contract.
cmdbytesThe arbitrary byte string containing the command data, structured specifically for the corresponding sidecar.
sudoboolIndicates if the command should be executed with superuser privileges.

readSlot

solidity
function readSlot(uint256 slot) public view returns (uint256 data)

Low-level view method for reading an arbitrary slot location in the BEX contract storage. This method only accepts the raw slot location. In most cases, ordinary users are better off using the higher-level Query contract to query information.

Parameters

NameTypeDescription
slotuint256The raw storage slot location to read from.

Returns

NameTypeDescription
datauint256The data stored at the specified storage slot location.