Developer Reference
For integrating with Glarex directly rather than through the app.
Chain ID: 46630
RPC: https://rpc.testnet.chain.robinhood.com
Explorer: https://explorer.testnet.chain.robinhood.com
Addresses are on Contracts & Addresses. ABIs are readable from the verified source on the explorer.
Integration flow
A swap is three steps:
- Quote — read the expected output for your input amount
- Approve — grant the router an allowance on the input token, once per token
- Swap — call the router, which executes the trade and pays cashback in the same transaction
Do not call the Uniswap pools or SwapRouter directly. Swaps that bypass GlarexRouter execute normally at the pool level but receive no cashback and are not attributed to your address for points.
Quoting
Quotes come from QuoterV2 at 0x1149564c0Cfa0260F9f00F4A0b5e324bB8e0BC03.
It is not a view function. It reverts internally and decodes the result, so it must be simulated with eth_call and never sent as a transaction.
Single hop
quoteExactInputSingle((address tokenIn, address tokenOut, uint256 amountIn, uint24 fee, uint160 sqrtPriceLimitX96))
Returns amountOut, sqrtPriceX96After, initializedTicksCrossed, gasEstimate.
Note the field order differs from the router’s swap struct — amountIn comes before fee here.
Multi hop
quoteExactInput(bytes path, uint256 amountIn)
Returns amountOut, sqrtPriceX96AfterList, initializedTicksCrossedList, gasEstimate.
Quote the encoded path in one call rather than quoting each leg separately.
Swapping
GlarexRouter exposes two entry points. Both take a single struct and both are exact-input.
Single hop
swapExactInputSingle(ExactInputSingleParams params)
Use when a direct pool exists for the pair.
| Field | Type | Notes |
|---|---|---|
tokenIn | address | Token you’re paying with |
tokenOut | address | Token you want |
fee | uint24 | Fee tier of the pool being used |
amountIn | uint256 | Gross amount, commission included — see below |
amountOutMinimum | uint256 | Slippage floor. Never pass 0. |
sqrtPriceLimitX96 | uint160 | Price limit; 0 disables it |
recipient | address | Receives the output tokens |
referrer | address | Referrer to bind, or the zero address |
Multi hop
swapExactInputPath(ExactInputPathParams params)
Use when the route goes through the hub. Both legs execute atomically.
| Field | Type | Notes |
|---|---|---|
path | bytes | Encoded route: token → fee → token → fee → token |
tokenIn | address | First token in the path |
tokenOut | address | Last token in the path |
amountIn | uint256 | Gross amount, commission included |
amountOutMinimum | uint256 | Slippage floor |
recipient | address | Receives the output tokens |
referrer | address | Referrer to bind, or the zero address |
There is no deadline field on either struct.
Commission and quoting
The commission is taken from the input side, before the trade reaches the pool.
Read commissionBps() from the router — do not hardcode 10. Then:
amountInyou pass to the router is the gross amount the user typed- The amount you should quote is
amountIn − (amountIn × commissionBps ÷ 10000)
Quoting the gross amount will overstate the output and produce an amountOutMinimum the swap can’t meet.
Slippage
Derive amountOutMinimum from your quote: amountOut × (10000 − slippageBps) ÷ 10000. The app defaults to 50 bps.
Read functions
| Function | Returns |
|---|---|
commissionBps() | Current commission in basis points |
MAX_COMMISSION_BPS() | Ceiling the commission can never exceed |
BPS_DENOMINATOR() | Denominator for basis point maths |
swapCount(address) | This user’s cumulative swap count |
referrerOf(address) | Bound referrer, or the zero address |
previewCashback(address) | (bool due, uint256 amount) for this user’s next swap |
previewCashbackAt(address, uint256) | Same, for a specific swap count |
cashbackToken() | GLRX address |
cashbackTreasury() | GLRX remaining for payouts |
cashbackMin() / cashbackMax() | Payout bounds |
CASHBACK_GUARANTEED_INTERVAL() | Swap interval that always pays |
CASHBACK_CHANCE_INTERVAL() | Swap interval eligible for a chance payout |
collectedFees(address) | Commission accumulated in a given token |
paused() | Whether swaps are halted |
Check paused() before building a swap — a paused router reverts every swap.
Cashback for integrators
Cashback is not paid on every swap. Call previewCashback(user) before submitting: it returns whether the next swap pays and how much. There is no guessing involved, and no transaction is needed to find out.
The payout is transferred in the same transaction as the swap, to the user, alongside a CashbackPaid event. When it doesn’t pay, CashbackSkipped is emitted instead — both are conclusive, so read the events rather than diffing balances.
If cashbackTreasury() is exhausted, swaps still execute and cashback is skipped. Never treat a missing payout as a failed swap.
Referrals
referrer is passed on every swap, but binding is permanent and first-write-wins. Once referrerOf(user) returns a non-zero address, later values are ignored.
Check referrerOf before passing anything: if it’s already set, the field does nothing.
Gas
Add a 30% buffer over your gas estimate on every swap submission.
A swap that crosses a tick boundary consumes more gas than one that doesn’t, and the estimator cannot know in advance which side of a boundary the trade lands on. Without the buffer, boundary-crossing swaps revert out of gas. Unused gas is refunded.
Events
GlarexRouter
Swap(address indexed user, address indexed tokenIn, address indexed tokenOut, uint256 amountIn, uint256 amountOut, uint256 commission, uint256 userSwapCount)
Topic0: 0x0874b2d545cb271cdbda4e093020c452328b24af12382ed62c4d00f5c26709db
| Field | Indexed | Notes |
|---|---|---|
user | yes | The trader, not the router |
tokenIn | yes | Input token |
tokenOut | yes | Output token |
amountIn | no | Gross input, commission included |
amountOut | no | Amount delivered to the recipient |
commission | no | Taken from the input side |
userSwapCount | no | This user’s cumulative swap number |
All three address fields are indexed, so you can filter by trader, by input token, or by output token without decoding data.
This is the event to index. One is emitted per swap regardless of how many pools the route touched, so counting router Swap events gives you trades — counting pool Swap events gives you legs.
CashbackPaid(address indexed user, uint256 amount, uint256 userSwapCount)
Topic0: 0x546c42c498622530a58042d2a267d045c4c46128e11b231c0e8e873534a13ca9
| Field | Indexed | Notes |
|---|---|---|
user | yes | Recipient of the cashback |
amount | no | GLRX paid, in wei |
userSwapCount | no | Matches the Swap event from the same transaction |
Emitted alongside a GLRX transfer to the user. userSwapCount is the join key between the two events — pair Swap and CashbackPaid on it rather than assuming log ordering.
A swap can settle without a CashbackPaid event. In that case CashbackSkipped(address indexed user, uint256 userSwapCount) is emitted instead — every swap produces exactly one of the two.
ReferralRegistered(address indexed user, address indexed referrer) fires once per user, on the swap where the binding is first written. It never fires again for that address.
Indexing from scratch: the router’s first block is 105444916. Nothing exists before it.
Pool events
Underlying Uniswap V3 pools emit their standard Swap event, plus ERC-20 Transfer and Approval events on the tokens. A two-hop route produces two pool Swap events and one router Swap event.
Index on the router address rather than on pool addresses — routing may change which pools a trade touches, but every Glarex swap passes through the router.
Reverts
| Revert | Cause | Fix |
|---|---|---|
Too little received | Output fell below amountOutMinimum between quote and execution | Re-quote, or raise slippage, or trade a smaller amount |
insufficient funds | Not enough ETH for gas | Claim from the Robinhood Chain gas faucet |
| Fee-on-transfer revert | The token takes a fee on transfer and can’t be routed | Not supported — use a different token |
Custom errors defined in the router are readable from the verified source on the explorer.
Cashback behaviour for integrators
Cashback is transferred in the same transaction as the swap, to the address that called the router. Two consequences:
- If you route user swaps through your own contract, the cashback lands on your contract, not on the end user. Forward it yourself if that’s not what you want.
- If the router’s GLRX balance is insufficient, the swap still succeeds and the cashback is skipped. Don’t treat a missing GLRX transfer as a failed swap.
Rate limits and RPC
The public RPC is shared infrastructure. For anything doing sustained polling, run your own node or use a dedicated provider. Polling the public endpoint aggressively will get you throttled, and a throttled quote is a stale quote.