Skip to main content

Asset Exchange Backend

Near Treasury utilizes the Rhea Finance SDK, which enables token swaps through its Smart Routing feature.

In this article you'll find additional information about RHEA and the Auto Router algorithm used to get better prices, and better liquidity utilization compared to regular exchanges.

About RHEA Finance

RHEA Finance is a community-led, multi-purpose DeFi platform built on the NEAR Protocol blockchain.

The platform is fully permissionless and removes the need for trusted intermediaries, prioritizing decentralization and censorship resistance. Anyone can trade or become a liquidity provider for a pool by depositing an equivalent value of each underlying token in return for pool tokens. These tokens track pro-rata LP shares of the total reserves, and can be redeemed for the underlying assets at any time.

info

RHEA Finance's smart contract (v2.ref-finance.near) swaps, provides liquidity, and contains all pairs or liquidity pools, made of reserves of two or three NEP-141 tokens (ERC-20 equivalent on NEAR).

RHEA Auto Router

Auto Router, also known as Smart Routing, can be defined as the ability to find better prices for traders on RHEA Finance. This includes splitting the trade across multiple pools at once.

The Auto Router offers better prices and better liquidity utilization, and ultimately creates a win-win situation for market participants:

  • Traders: better prices
  • Liquidity Providers: fairer model (vs winner-takes-all approach)
tip

The Auto Router algorithm is open source, and available at RHEA Finance GitHub repository.

Auto Router Design

RHEA Finance's Auto Router aims to find the best price for a trade. The algorithm takes advantage of all liquidity, using all pools when available:

  • Parallel pools
  • Intermediary pools

The Auto Router solution determines the best allocation across pools of the same pairs, and the best path using one hop or intermediary pool.

info

The Auto Router also leverages the StableSwap function, therefore combining both, normal and stable pools as potential intermediary pools.

Here's a high-level flow chart of the Auto Router logic:

smart router