Welcome back! In Chapter 5: SelfPeggingAsset Factory, we learned how new SelfPeggingAsset (SPA) Pools and their associated tokens are created using a standardized “assembly line”. When setting up these pools, especially for tokens that might not always be worth exactly the same (like different stablecoins, or tokens representing staked assets), the factory needs to tell the pool how to find out the current real-world value of those tokens.
Imagine our SelfPeggingAsset (SPA) Pool is like an exchange booth trying to swap US Dollars (USD) for Euros (EUR). To offer a fair exchange rate and calculate its service fee correctly, the booth needs to know the current market rate – is 1 EUR worth $1.05 today, or $1.10? It can’t just guess or use yesterday’s rate.
Similarly, our SPA Pool holds different digital tokens. Let’s say it holds USDC and USDT. While both aim to be worth $1, tiny differences in their market prices can exist. Or imagine a pool holding stETH (staked Ether) and WETH (Wrapped Ether). Their values are closely related but not always exactly 1:1.
The SPA Pool needs a way to look up the current approximate real-world exchange rate for the tokens it holds. This information is crucial for:
Where does the pool get this vital price information? From Exchange Rate Providers!
Exchange Rate Providers are specialized smart contracts that act like trusted price tickers for the blockchain. Think of them like subscribing to a financial news feed (like Bloomberg or Reuters) that constantly reports the latest stock prices or currency exchange rates.
Each Exchange Rate Provider contract is designed to fetch or calculate the price for a specific type of token:
exchangeRate()
, that the SelfPeggingAsset (SPA) Pool can call to get the latest price information whenever needed.The SelfPeggingAsset Factory selects and configures the correct Exchange Rate Provider for each token when it creates a new pool.
The SelfPeggingAsset (SPA) Pool doesn’t store the exchange rates itself; it queries the providers when necessary.
Example Scenario: During a Swap