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
Name | Type | Description |
---|---|---|
tokenInfo | swapTokenInfo | Specifies the inputs and outputs of the swap |
pathDefinition | bytes | Encoded path parameters of the swap path |
executor | address | External contract that will execute the path |
referralCode | uint32 | Referral code to note the source of the swap |
swapTokenInfo
struct:
Name | Type | Description |
---|---|---|
inputToken | address | Token starting the swap. The native token (BERA) is 0x0000000000000000000000000000000000000000 |
inputAmount | uint256 | Amount of inputToken to swap |
outputToken | address | Token returning from swap. The native token (BERA) is 0x0000000000000000000000000000000000000000 |
outputQuote | uint256 | Expected amount returned |
outputMin | uint256 | Minimum amount returned derived from slippage and quote |
outputReceiver | address | The destination address to receive output tokens |
Return
Name | Type | Description |
---|---|---|
amountOut | uint256 | Actual 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
);
Name | Type | Description |
---|---|---|
sender | address | Address that called the swap |
inputAmount | uint256 | Amount of inputTokens used |
inputToken | address | Token that started the swap. The native token (BERA) is 0x0000000000000000000000000000000000000000 |
amountOut | uint256 | Actual amountOut transferred after potential fees |
outputToken | address | Token that returned from the swap. The native token (BERA) is 0x0000000000000000000000000000000000000000 |
slippage | int256 | The 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) |
referralCode | uint32 | Used to identify the source of the swap |
Errors
Selector | Signature | Description |
---|---|---|
0x71c4efed | SlippageExceeded(uint256,uint256) | amountOut resulted lower than outputMin during swap execution |
0xfa463c69 | SameTokenInAndOut(address) | Cannot provide same inputToken and outputToken |
0x6da58071 | MinimumOutputGreaterThanQuote(uint256,uint256) | outputMin is set greater than outputQuote |
0xf067d762 | MinimumOutputIsZero() | outputMin is set to 0 |
0xdb4d141c | NativeDepositValueMismatch(uint256,uint256) | value provided to function call does not match amountIn provided when inputToken is the native token |
0x9996b315 | AddressEmptyCode(address) | Calling a contract that has no bytecode |
0xcd786059 | AddressInsufficientBalance(address) | Attempting to send native token with insufficient balance |
0xd93c0665 | EnforcedPause() | Function can only be called when the contract is unpaused |
0x8dfc202b | ExpectedPause() | Function can only be called when the contract is paused |
0x1425ea42 | FailedInnerCall() | A call to an address target failed. The target may have reverted. |
0x79feaaea | InvalidNativeTransfer() | Native token transfer has failed |
0x5274afe7 | SafeERC20FailedOperation(address) | An operation with an ERC-20 token failed. |