> For the complete documentation index, see [llms.txt](https://docs.oogabooga.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.oogabooga.io/deployments/aggregator/obrouter-reference.md).

# OBRouter Reference

## Functions

The swap function is the primary function interface for making swaps through Ooga Booga.

```solidity
function swap(
  swapTokenInfo memory tokenInfo,
  bytes calldata pathDefinition,
  address executor,
  uint32 referralCode
) external payable returns (uint256 amountOut)
```

| 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 |

{% hint style="info" %}
When `inputAmount` is set to 0 then the senders' full balance will be sent. This can be used to fully swap tokens that rebase.
{% endhint %}

{% hint style="warning" %}
Do not modify the calldata provided by the swap endpoint. It could lead to **loss of funds**. The calldata provided should allow direct execution on-chain.
{% endhint %}

The structure of the data returned is:

| Name        | Type      | Description                                  |
| ----------- | --------- | -------------------------------------------- |
| `amountOut` | `uint256` | Actual outputToken amount received from swap |

The `swapTokenInfo` struct looks like:

| 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                                                   |

## Events

An event is emitted from any swaps carried out on `OBRouter`:

```solidity
event Swap(
    address sender,
    uint256 inputAmount,
    address inputToken,
    uint256 amountOut,
    address outputToken,
    int256 slippage,
    uint32 referralCode
);
```

The structure of the data within the event emitted looks like this:

| 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

These are the errors that can occur:

| 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.                                                                  |

## ABI

Finally, this is the ABI for `OBRouter`:

```
[
  {
    "type": "constructor",
    "inputs": [
      {
        "name": "_owner",
        "type": "address",
        "internalType": "address"
      }
    ],
    "stateMutability": "nonpayable"
  },
  {
    "type": "receive",
    "stateMutability": "payable"
  },
  {
    "type": "function",
    "name": "FEE_DENOM",
    "inputs": [],
    "outputs": [
      {
        "name": "",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "stateMutability": "view"
  },
  {
    "type": "function",
    "name": "REFERRAL_WITH_FEE_THRESHOLD",
    "inputs": [],
    "outputs": [
      {
        "name": "",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "stateMutability": "view"
  },
  {
    "type": "function",
    "name": "owner",
    "inputs": [],
    "outputs": [
      {
        "name": "",
        "type": "address",
        "internalType": "address"
      }
    ],
    "stateMutability": "view"
  },
  {
    "type": "function",
    "name": "pause",
    "inputs": [],
    "outputs": [],
    "stateMutability": "nonpayable"
  },
  {
    "type": "function",
    "name": "paused",
    "inputs": [],
    "outputs": [
      {
        "name": "",
        "type": "bool",
        "internalType": "bool"
      }
    ],
    "stateMutability": "view"
  },
  {
    "type": "function",
    "name": "referralLookup",
    "inputs": [
      {
        "name": "",
        "type": "uint32",
        "internalType": "uint32"
      }
    ],
    "outputs": [
      {
        "name": "referralFee",
        "type": "uint64",
        "internalType": "uint64"
      },
      {
        "name": "beneficiary",
        "type": "address",
        "internalType": "address"
      },
      {
        "name": "registered",
        "type": "bool",
        "internalType": "bool"
      }
    ],
    "stateMutability": "view"
  },
  {
    "type": "function",
    "name": "registerReferralCode",
    "inputs": [
      {
        "name": "_referralCode",
        "type": "uint32",
        "internalType": "uint32"
      },
      {
        "name": "_referralFee",
        "type": "uint64",
        "internalType": "uint64"
      },
      {
        "name": "_beneficiary",
        "type": "address",
        "internalType": "address"
      }
    ],
    "outputs": [],
    "stateMutability": "nonpayable"
  },
  {
    "type": "function",
    "name": "renounceOwnership",
    "inputs": [],
    "outputs": [],
    "stateMutability": "nonpayable"
  },
  {
    "type": "function",
    "name": "swap",
    "inputs": [
      {
        "name": "tokenInfo",
        "type": "tuple",
        "internalType": "struct IOBRouter.swapTokenInfo",
        "components": [
          {
            "name": "inputToken",
            "type": "address",
            "internalType": "address"
          },
          {
            "name": "inputAmount",
            "type": "uint256",
            "internalType": "uint256"
          },
          {
            "name": "outputToken",
            "type": "address",
            "internalType": "address"
          },
          {
            "name": "outputQuote",
            "type": "uint256",
            "internalType": "uint256"
          },
          {
            "name": "outputMin",
            "type": "uint256",
            "internalType": "uint256"
          },
          {
            "name": "outputReceiver",
            "type": "address",
            "internalType": "address"
          }
        ]
      },
      {
        "name": "pathDefinition",
        "type": "bytes",
        "internalType": "bytes"
      },
      {
        "name": "executor",
        "type": "address",
        "internalType": "address"
      },
      {
        "name": "referralCode",
        "type": "uint32",
        "internalType": "uint32"
      }
    ],
    "outputs": [
      {
        "name": "amountOut",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "stateMutability": "payable"
  },
  {
    "type": "function",
    "name": "swapERC20Permit",
    "inputs": [
      {
        "name": "permit",
        "type": "tuple",
        "internalType": "struct IOBRouter.erc20PermitInfo",
        "components": [
          {
            "name": "value",
            "type": "uint256",
            "internalType": "uint256"
          },
          {
            "name": "deadline",
            "type": "uint256",
            "internalType": "uint256"
          },
          {
            "name": "v",
            "type": "uint8",
            "internalType": "uint8"
          },
          {
            "name": "r",
            "type": "bytes32",
            "internalType": "bytes32"
          },
          {
            "name": "s",
            "type": "bytes32",
            "internalType": "bytes32"
          }
        ]
      },
      {
        "name": "tokenInfo",
        "type": "tuple",
        "internalType": "struct IOBRouter.swapTokenInfo",
        "components": [
          {
            "name": "inputToken",
            "type": "address",
            "internalType": "address"
          },
          {
            "name": "inputAmount",
            "type": "uint256",
            "internalType": "uint256"
          },
          {
            "name": "outputToken",
            "type": "address",
            "internalType": "address"
          },
          {
            "name": "outputQuote",
            "type": "uint256",
            "internalType": "uint256"
          },
          {
            "name": "outputMin",
            "type": "uint256",
            "internalType": "uint256"
          },
          {
            "name": "outputReceiver",
            "type": "address",
            "internalType": "address"
          }
        ]
      },
      {
        "name": "pathDefinition",
        "type": "bytes",
        "internalType": "bytes"
      },
      {
        "name": "executor",
        "type": "address",
        "internalType": "address"
      },
      {
        "name": "referralCode",
        "type": "uint32",
        "internalType": "uint32"
      }
    ],
    "outputs": [
      {
        "name": "amountOut",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "stateMutability": "nonpayable"
  },
  {
    "type": "function",
    "name": "swapPermit2",
    "inputs": [
      {
        "name": "permit2",
        "type": "tuple",
        "internalType": "struct IOBRouter.permit2Info",
        "components": [
          {
            "name": "contractAddress",
            "type": "address",
            "internalType": "address"
          },
          {
            "name": "nonce",
            "type": "uint256",
            "internalType": "uint256"
          },
          {
            "name": "deadline",
            "type": "uint256",
            "internalType": "uint256"
          },
          {
            "name": "signature",
            "type": "bytes",
            "internalType": "bytes"
          }
        ]
      },
      {
        "name": "tokenInfo",
        "type": "tuple",
        "internalType": "struct IOBRouter.swapTokenInfo",
        "components": [
          {
            "name": "inputToken",
            "type": "address",
            "internalType": "address"
          },
          {
            "name": "inputAmount",
            "type": "uint256",
            "internalType": "uint256"
          },
          {
            "name": "outputToken",
            "type": "address",
            "internalType": "address"
          },
          {
            "name": "outputQuote",
            "type": "uint256",
            "internalType": "uint256"
          },
          {
            "name": "outputMin",
            "type": "uint256",
            "internalType": "uint256"
          },
          {
            "name": "outputReceiver",
            "type": "address",
            "internalType": "address"
          }
        ]
      },
      {
        "name": "pathDefinition",
        "type": "bytes",
        "internalType": "bytes"
      },
      {
        "name": "executor",
        "type": "address",
        "internalType": "address"
      },
      {
        "name": "referralCode",
        "type": "uint32",
        "internalType": "uint32"
      }
    ],
    "outputs": [
      {
        "name": "amountOut",
        "type": "uint256",
        "internalType": "uint256"
      }
    ],
    "stateMutability": "nonpayable"
  },
  {
    "type": "function",
    "name": "transferOwnership",
    "inputs": [
      {
        "name": "newOwner",
        "type": "address",
        "internalType": "address"
      }
    ],
    "outputs": [],
    "stateMutability": "nonpayable"
  },
  {
    "type": "function",
    "name": "transferRouterFunds",
    "inputs": [
      {
        "name": "tokens",
        "type": "address[]",
        "internalType": "address[]"
      },
      {
        "name": "amounts",
        "type": "uint256[]",
        "internalType": "uint256[]"
      },
      {
        "name": "dest",
        "type": "address",
        "internalType": "address"
      }
    ],
    "outputs": [],
    "stateMutability": "nonpayable"
  },
  {
    "type": "function",
    "name": "unpaused",
    "inputs": [],
    "outputs": [],
    "stateMutability": "nonpayable"
  },
  {
    "type": "event",
    "name": "OwnershipTransferred",
    "inputs": [
      {
        "name": "previousOwner",
        "type": "address",
        "indexed": true,
        "internalType": "address"
      },
      {
        "name": "newOwner",
        "type": "address",
        "indexed": true,
        "internalType": "address"
      }
    ],
    "anonymous": false
  },
  {
    "type": "event",
    "name": "Paused",
    "inputs": [
      {
        "name": "account",
        "type": "address",
        "indexed": false,
        "internalType": "address"
      }
    ],
    "anonymous": false
  },
  {
    "type": "event",
    "name": "Swap",
    "inputs": [
      {
        "name": "sender",
        "type": "address",
        "indexed": false,
        "internalType": "address"
      },
      {
        "name": "inputAmount",
        "type": "uint256",
        "indexed": false,
        "internalType": "uint256"
      },
      {
        "name": "inputToken",
        "type": "address",
        "indexed": false,
        "internalType": "address"
      },
      {
        "name": "amountOut",
        "type": "uint256",
        "indexed": false,
        "internalType": "uint256"
      },
      {
        "name": "outputToken",
        "type": "address",
        "indexed": false,
        "internalType": "address"
      },
      {
        "name": "slippage",
        "type": "int256",
        "indexed": false,
        "internalType": "int256"
      },
      {
        "name": "referralCode",
        "type": "uint32",
        "indexed": false,
        "internalType": "uint32"
      }
    ],
    "anonymous": false
  },
  {
    "type": "event",
    "name": "Unpaused",
    "inputs": [
      {
        "name": "account",
        "type": "address",
        "indexed": false,
        "internalType": "address"
      }
    ],
    "anonymous": false
  },
  {
    "type": "error",
    "name": "AddressEmptyCode",
    "inputs": [
      {
        "name": "target",
        "type": "address",
        "internalType": "address"
      }
    ]
  },
  {
    "type": "error",
    "name": "AddressInsufficientBalance",
    "inputs": [
      {
        "name": "account",
        "type": "address",
        "internalType": "address"
      }
    ]
  },
  {
    "type": "error",
    "name": "EnforcedPause",
    "inputs": []
  },
  {
    "type": "error",
    "name": "ExpectedPause",
    "inputs": []
  },
  {
    "type": "error",
    "name": "FailedInnerCall",
    "inputs": []
  },
  {
    "type": "error",
    "name": "FeeTooHigh",
    "inputs": [
      {
        "name": "fee",
        "type": "uint64",
        "internalType": "uint64"
      }
    ]
  },
  {
    "type": "error",
    "name": "InvalidFeeForCode",
    "inputs": [
      {
        "name": "fee",
        "type": "uint64",
        "internalType": "uint64"
      }
    ]
  },
  {
    "type": "error",
    "name": "InvalidNativeTransfer",
    "inputs": []
  },
  {
    "type": "error",
    "name": "InvalidRouterFundsTransfer",
    "inputs": []
  },
  {
    "type": "error",
    "name": "MinimumOutputGreaterThanQuote",
    "inputs": [
      {
        "name": "outputMin",
        "type": "uint256",
        "internalType": "uint256"
      },
      {
        "name": "outputQuote",
        "type": "uint256",
        "internalType": "uint256"
      }
    ]
  },
  {
    "type": "error",
    "name": "MinimumOutputIsZero",
    "inputs": []
  },
  {
    "type": "error",
    "name": "NativeDepositValueMismatch",
    "inputs": [
      {
        "name": "expected",
        "type": "uint256",
        "internalType": "uint256"
      },
      {
        "name": "received",
        "type": "uint256",
        "internalType": "uint256"
      }
    ]
  },
  {
    "type": "error",
    "name": "NullBeneficiary",
    "inputs": []
  },
  {
    "type": "error",
    "name": "OwnableInvalidOwner",
    "inputs": [
      {
        "name": "owner",
        "type": "address",
        "internalType": "address"
      }
    ]
  },
  {
    "type": "error",
    "name": "OwnableUnauthorizedAccount",
    "inputs": [
      {
        "name": "account",
        "type": "address",
        "internalType": "address"
      }
    ]
  },
  {
    "type": "error",
    "name": "ReferralCodeInUse",
    "inputs": [
      {
        "name": "referralCode",
        "type": "uint32",
        "internalType": "uint32"
      }
    ]
  },
  {
    "type": "error",
    "name": "SafeERC20FailedOperation",
    "inputs": [
      {
        "name": "token",
        "type": "address",
        "internalType": "address"
      }
    ]
  },
  {
    "type": "error",
    "name": "SameTokenInAndOut",
    "inputs": [
      {
        "name": "token",
        "type": "address",
        "internalType": "address"
      }
    ]
  },
  {
    "type": "error",
    "name": "SlippageExceeded",
    "inputs": [
      {
        "name": "amountOut",
        "type": "uint256",
        "internalType": "uint256"
      },
      {
        "name": "outputMin",
        "type": "uint256",
        "internalType": "uint256"
      }
    ]
  }
]
```
