Skip to content

Contract Reference

OBRouter Contract

Functions

Swap

This is the main function interface for making swaps with the Ooga Booga Router.

The swap parameters to be passed must be queried from swap endpoint

IMPORTANT

When inputAmount is set to 0 then the senders' full balance will be sent in. This is used to fully swap ERC-20 tokens that rebase.

CAUTION

Do not modify the calldata provided by the swap endpoint, otherwise it could lead to loss of funds. The calldata provided should allow direct execution on-chain

solidity
function swap(
  swapTokenInfo memory tokenInfo, 
  bytes calldata pathDefinition, 
  address executor, 
  uint32 referralCode
) external payable returns (uint256 amountOut)
solidity
struct swapTokenInfo {
    address inputToken;
    uint256 inputAmount;
    address outputToken;
    uint256 outputQuote;
    uint256 outputMin;
    address outputReceiver;
}
Parameters
NameTypeDescription
tokenInfoswapTokenInfoSpecifies the inputs and outputs of the swap
pathDefinitionbytesEncoded path parameters of the swap path
executoraddressExternal contract that will execute the path
referralCodeuint32Referral code to note the source of the swap

swapTokenInfo struct:

NameTypeDescription
inputTokenaddressToken starting the swap. The native token (BERA) is 0x0000000000000000000000000000000000000000
inputAmountuint256Amount of inputToken to swap
outputTokenaddressToken returning from swap. The native token (BERA) is 0x0000000000000000000000000000000000000000
outputQuoteuint256Expected amount returned
outputMinuint256Minimum amount returned derived from slippage and quote
outputReceiveraddressThe destination address to receive output tokens
Return
NameTypeDescription
amountOutuint256Actual outputToken amount received from swap

Events

Swap

This event is emitted from any swaps carried out on the OBRouter contract

solidity
event Swap(
    address sender,
    uint256 inputAmount,
    address inputToken,
    uint256 amountOut,
    address outputToken,
    int256 slippage,
    uint32 referralCode
);
NameTypeDescription
senderaddressAddress that called the swap
inputAmountuint256Amount of inputTokens used
inputTokenaddressToken that started the swap. The native token (BERA) is 0x0000000000000000000000000000000000000000
amountOutuint256Actual amountOut transferred after potential fees
outputTokenaddressToken that returned from the swap. The native token (BERA) is 0x0000000000000000000000000000000000000000
slippageint256The difference between the expected outputQuote and actual amountOut returned (slippage = amountOut - outputQuote). When < 0 means negative slippage (swap returned less than expected) and > 0 positive slippage (swap returned more than expected)
referralCodeuint32Used to identify the source of the swap

Errors

SelectorSignatureDescription
0x71c4efedSlippageExceeded(uint256,uint256)amountOut resulted lower than outputMin during swap execution
0xfa463c69SameTokenInAndOut(address)Cannot provide same inputToken and outputToken
0x6da58071MinimumOutputGreaterThanQuote(uint256,uint256)outputMin is set greater than outputQuote
0xf067d762MinimumOutputIsZero()outputMin is set to 0
0xdb4d141cNativeDepositValueMismatch(uint256,uint256)value provided to function call does not match amountIn provided when inputToken is the native token
0x9996b315AddressEmptyCode(address)Calling a contract that has no bytecode
0xcd786059AddressInsufficientBalance(address)Attempting to send native token with insufficient balance
0xd93c0665EnforcedPause()Function can only be called when the contract is unpaused
0x8dfc202bExpectedPause()Function can only be called when the contract is paused
0x1425ea42FailedInnerCall()A call to an address target failed. The target may have reverted.
0x79feaaeaInvalidNativeTransfer()Native token transfer has failed
0x5274afe7SafeERC20FailedOperation(address)An operation with an ERC-20 token failed.