Documentation
How Peglo prices stablecoin FX on 1inch Aqua, protects liquidity providers when a coin breaks, and uses Chainlink CRE for rates and halts.
Overview
Peglo turns any wallet holding stablecoins into a market maker without a deposit. A liquidity provider (a maker) ships strategies to 1inch Aqua. Aqua only records what each strategy may use; tokens leave the wallet only when a trade fills, straight to the trader.
One wallet balance can do two jobs at once:
- FX range (SwapVM opcode 34). One strategy prices up to 8 stablecoins on one curve: USDC, USDT, DAI, USDS and USDe at $1, and EURC, BRZ and IDRX at live euro, real and rupiah rates. It earns a fee on every trade it fills.
- Backstop (SwapVM opcode 35). Dormant while every coin is healthy. When Chainlink CRE halts a coin, it buys that coin below market and pays in healthy coins, never above face value.
A Chainlink CRE workflow sets the FX rates every swap uses and decides when a coin is broken. Trades are split across every maker and settle on both the Peglo router and 1inch's official router in one transaction.
A worked example
On our Base mainnet fork, one maker wallet holds $320,019 in eight stablecoins. It runs a Tight FX range worth $320,019 and, from the same balance, a backstop pledging $60,000 of USDC and USDT. That is $380,019 of strategies on a $320,019 wallet: a shared liquidity ratio of 1.19x, with every coin still in the wallet.
Solana
The same two jobs run as a native Solana program. Opening a strategy approves the Peglo program as an SPL token delegate for the coins it uses, the Solana version of an Aqua allowance. Coins stay in your own token accounts. When a trade fills, the program takes the taker's coin into your wallet and pays the other coin out of it, in one instruction per leg. Ranges use the same sphere curve and backstops the same discount curve as the EVM contracts.
| Network | Program | Oracle |
|---|---|---|
| Solana mainnet | 9yndJ2CVGSWr58nXNVS8rgkYFiiXghkchicSK5KjhABw | A6DuBEhUJYfhe2V3nPSkjoxJCZw8j2Q8aTbo98WDbdpm |
| Solana devnet | 9yndJ2CVGSWr58nXNVS8rgkYFiiXghkchicSK5KjhABw | A6DuBEhUJYfhe2V3nPSkjoxJCZw8j2Q8aTbo98WDbdpm |
Coins on Solana mainnet
| Coin | Mint | Decimals | Token program |
|---|---|---|---|
| USDC | EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v | 6 | SPL Token |
| USDT | Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB | 6 | SPL Token |
| PYUSD | 2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo | 6 | Token-2022 |
| USDG | 2u1tszSeqZ3qBWF3uNGPFc8TzMk2tdiwknnRMWGWjGWH | 6 | Token-2022 |
| USDS | USDSwr9ApdHk5bvJKMjzff41FfuX8bSxdKcR81vTwcA | 6 | SPL Token |
| USDe | DEkqHyPN7GMRJ5cArtQFAWefqbZb33Hyf6s5iCwjEonT | 9 | SPL Token |
| EURC | HzwqbKZw8HxMN6bF2yFZNrht3c2iXXzpKcFu7uBEDKtr | 6 | SPL Token |
| BRZ | FtgGSFADXBtroxq8VCausXRr2of47QBf5AS1NtZCu4GD | 4 | SPL Token |
Devnet uses test copies of these coins with the same decimals. Anyone can mint them from the account menu with Get test coins.
Prices and halts
- Dollar coins count at $1. EURC and BRZ use the rate the sentinel last reported.
- The sentinel runs the same policy as the Chainlink CRE workflow: it checks Pyth price accounts, ECB rates, CoinGecko and DefiLlama, halts a coin at 3% off peg (0.75% when both sides agree), and lifts the halt inside 0.25%.
- A reported rate expires after 15 minutes on mainnet. FX ranges with an expired rate pause, dollar pairs keep trading.
- A halted coin is refused by ranges and bought only by backstops, at its reported market price minus the discount, never above face value.
- The guardian (the oracle admin) can halt or resume a coin by hand.
Wallets and costs
- Phantom, Solflare, Backpack and any Wallet Standard wallet connect from the account menu.
- A swap costs the normal Solana fee and about 50,000 compute units per leg. Your coin goes straight to the LP and theirs straight to you.
- Opening a strategy locks 0.0027 SOL of rent, returned when you close it, plus 0.0015 SOL for any token account your wallet does not have yet.
- Closing a strategy also revokes the delegate approval once no other strategy of yours uses that coin.
- Each token account has one delegate, so opening a strategy replaces any other delegate approval on that account.
- The program has not been audited. On mainnet, keep strategies small.
Quick start
- 1.Connect a wallet on Base. If your wallet does not know the network, the app offers to add it.
- 2.Swap: pick two coins and an amount. Check the route, the rate and "Value vs Chainlink", choose a slippage limit, then Swap. The first trade in a coin asks for one approval.
- 3.Provide: on Liquidity, choose FX range, pick the coins you hold (two or more), a width and a venue, and a dollar amount per coin. Open FX range approves Aqua for each coin, then ships the strategy. Nothing leaves your wallet.
- 4.Insure: on Liquidity, choose Backstop, pick the coins you pay out in, a discount preset, the pledge per coin and a cap per halted coin, then Pledge backstop.
- 5.Watch: Pool shows totals, depth and fees; Activity shows every fill, strategy change and Chainlink CRE report. Close any strategy from Liquidity at any time.
Concepts
| Term | Meaning |
|---|---|
| Maker | A wallet that ships strategies. It keeps its coins and can spend them at any time. |
| Taker | Anyone who trades against strategies, through the app, the batch taker or a router directly. |
ship | Registers a strategy on Aqua with the amounts it may use. Nothing is transferred. |
dock | Closes a strategy. Aqua forgets its amounts; there is nothing to withdraw. |
pull / push | During a fill Aqua pulls the output coin from the maker wallet to the taker and pushes the input coin into the maker wallet. |
| Strategy balance | Aqua's record of what a strategy may still use. It moves with every fill, so it is the range's live reserves. |
| Venue | Where a strategy is priced: the Peglo router (native opcodes) or 1inch AquaSwapVMRouter (through Extruction). |
| Shared liquidity ratio | Value of all strategies a wallet backs, divided by the value of the wallet. Above 1 means one balance is doing more than one job. |
| Spendable | The lower of a maker's wallet balance and its Aqua allowance. A fill never asks for more; the router skips a maker that is short. |
| Halt | A flag on a coin set by Chainlink CRE or the guardian. Ranges refuse a halted coin as input; only backstops buy it. |
Strategy lifecycle
- 1.Approve Aqua for each coin the strategy may pay out.
- 2.
shipthe strategy with its program (the opcode and packed config) and the amount for each coin. - 3.Takers fill it. Each fill moves the strategy balance and the actual coins in the same transaction.
- 4.
dockit whenever you want. Docking only clears the record; your coins never left.
FX ranges
A range is a concentrated position on a sphere over the coins you pick (2 to 8). Each coin counts at its USD value: $1 for the dollar coins, the live rate for EURC, BRZ and IDRX. Every coin trades against every other, so n coins give n × (n − 1) swap directions from one position.
| Width | Capital efficiency | Edge at | Fee, USD pairs | Fee, FX pairs |
|---|---|---|---|---|
| Tight | 301x | 0.5% depeg | 0.01% | 0.05% |
| Balanced | 61x | 2.0% depeg | 0.04% | 0.10% |
| Wide | 11x | 8.0% depeg | 0.10% | 0.30% |
Capital efficiency comes from a floor added to every balance: the range behaves like a pool many times its size near the peg, and runs out of depth sooner when a coin drifts. On a pool with $1M per coin, a $10k trade moves the price 0.41 bps in a Tight range, 2.0 in Balanced, 11 in Wide, and 122 with no concentration.
The edge and the exposure cap
When a coin floods into a range, the range reaches its edge and refuses that coin, while every other pair keeps trading. An exposure cap limits how much of any one coin a range can end up holding: 2 / n of its value by default (25% with 8 coins, 40% with 5). In a crash to $0.80, a Tight range loses 7.85% with the edge against 19.3% without it, while simply holding the five coins loses 4%.
Spending while providing
You can spend from your wallet at any time. A fill checks your live balance and allowance first; if you no longer hold enough of the output coin, the router routes around you instead of failing the trade. Your range keeps quoting the coins you still hold.
Currency risk
A range that includes EURC, BRZ or IDRX ends up holding some of them as trades flow through. If the euro, real or rupiah falls against the dollar, so does the dollar value of the range. A range over dollar coins only has no currency risk, only depeg risk.
Backstops
A backstop pledges payout coins (for example USDC and USDT) and covers every coin in the pool, payout coins included: if USDC halts, it pays in USDT, and the USDC it already holds counts toward the cap. It does nothing until Chainlink CRE or the guardian halts a coin. Then it buys that coin, exact input only, and pays in a healthy coin.
| Preset | Discount when empty | Discount when full | Pays at a $0.93 depeg |
|---|---|---|---|
| Light | 1% | 5% | $0.921 to $0.884 |
| Standard | 2% | 10% | $0.911 to $0.837 |
| Deep | 5% | 25% | $0.884 to $0.698 |
- The price is the depeg market price (the lower of the fresh CRE price and the Chainlink market feed) minus the discount, and never above face value.
- The cap is per halted coin, in USD at face value. The discount grows linearly as the cap fills, so the first sellers get the best price.
- Discounts can be set up to 50%. A halted coin is never paid out.
- The coins it buys land in your wallet. If the coin recovers, they are worth face value again and the backstop has earned its discount; if it keeps falling, the backstop loses.
- On our fork, a USDe crash to $0.93 left the two backstops up 1.86% and 1.12%.
Routing
- The SDK finds every live strategy from Aqua's Shipped and Docked events, reads their balances, each maker's spendable amounts and the oracle prices.
- For a healthy input coin only FX ranges quote. For a halted input coin only backstops quote.
- The trade is cut into 64 slices. Each slice goes to the strategy that pays the most for it; slices halve near the limits so nothing is left unfilled that could be filled.
- A strategy drops out when the next slice would hit its edge, its exposure cap, or the maker's spendable balance. Your own strategies are skipped when you trade.
- PegloBatchTaker pulls the total input once, fills every leg on its router, then checks your minimum output and a 10 minute deadline. Either every leg fills or the whole trade reverts.
- Because the SDK runs the same bigint math as the contracts, quotes equal on-chain results to the wei.
Fees
- Each range charges its width fee on the input of every fill: 0.01%, 0.04% or 0.10% when both coins are dollar coins, and 0.05%, 0.10% or 0.30% when either is EURC, BRZ or IDRX.
- The whole input lands in the maker wallet while the price is computed on the input after the fee, so the fee grows the range and compounds to the LP.
- Peglo takes no protocol fee and has no token.
- Backstops do not charge a fee; they earn their discount.
- The Pool page sums fees paid to LPs over the last 24 hours, fill by fill, from the routers' Swapped events.
Pricing math
The pricing follows Paradigm's research on AMMs for many stablecoins, extended to live FX rates. For a range over n coins, with Aqua balance x, USD rate rho and floor m:
The radius is recomputed from live balances on every swap, so fees grow it and compound to the LP. S and Q are the sum and the sum of squares of v:
Only the two traded balances move, so the output is one square root in closed form, rounded in favor of the LP:
At the centre every coin trades at its USD rate; the price of coin i in coin j is
Edge, LP safety and the backstop price:
A is what the backstop already absorbed, a the incoming sale and C its cap. Rates are scaled to 18 decimals per token, so IDRX (2 decimals), USDC (6) and DAI (18) price on the same curve.
Chainlink CRE
The workflow (cre/depeg-sentinel, Go) runs every 30 seconds. It reads every oracle status and Chainlink feed in one Multicall3 call, fetches CoinGecko and DefiLlama with a median across nodes, decides, and writes one signed report to PegloOracle.
| Rule | Value |
|---|---|
| Halt | Every configured API at least 3% off peg, or the Chainlink feed alone at least 3% off |
| Soft halt | Both the APIs and the Chainlink feed at least 0.75% off |
| Resume | The closest API quote and the Chainlink feed back within 0.25% of peg |
| Rate push | On a 2 bp move, or every 10 minutes |
| Peg reference | $1 for dollar coins; the Chainlink EUR, BRL or IDR rate for FX coins |
| Reported price | Healthy: the API quote closest to the reference. Halted: the lowest market price, the safe side for backstops |
Price used for each coin
| Coin | Swaps | When halted |
|---|---|---|
| USDC, USDT, DAI, USDS, USDe | $1 | Refused as input; backstops buy at the lower of the CRE price and the Chainlink market feed |
| EURC, BRZ, IDRX | CRE rate if under 15 minutes old and within 0.5% of the Chainlink feed, else the feed; a feed older than 75 minutes pauses swaps | Same as above |
What the oracle accepts
- Reports only from the Chainlink forwarder and only from the set workflow owner. Before an owner is set, every report is refused.
- Reports stamped more than 5 minutes in the future are refused. Older reports never overwrite newer ones.
- A guardian can halt or resume a coin by hand. A calm CRE report does not lift a guardian halt.
A halt, step by step
- 1.A coin trades 3% or more off peg on every API, or on Chainlink.
- 2.The next run writes a report marking it halted, at its lowest market price.
- 3.Every range on both routers refuses the coin as input; healthy pairs keep trading.
- 4.Backstops start buying it below market, until their caps fill.
- 5.When the price is back within 0.25%, a later run lifts the halt and ranges accept the coin again.
Using the app
| Page | What it does |
|---|---|
| Swap | Quotes any pair, splits the trade across makers on both routers, and shows the route, the rate and the value against Chainlink. A halted coin can only be sold to backstops. |
| Liquidity | Open an FX range over coins you hold, or pledge a backstop. Shows your wallet, the shared liquidity ratio and your strategies, each with Close. |
| Pool | Totals, 24 hour volume and fees, depth of any coin by price drop, reserve mix, liquidity by depeg tolerance, the orbit map and every strategy. |
| Activity | Swaps, strategies opened or closed, and Chainlink CRE and guardian events, read from the chain, with explorer links. |
| Depeg | Local fork only. Crashes a coin through a local price API, runs the real CRE workflow and dumps the coin, to show ranges refuse it and backstops buy it. |
Contracts
| Contract | Role |
|---|---|
| PegloRouter | SwapVM v1.0.2 Aqua router with two new instructions: PegloTick (opcode 34) and PegloBackstop (opcode 35). |
| PegloExtruction | Range pricing for the official 1inch router, reached through Extruction (opcode 32). |
| PegloBackstop | Backstop pricing for both routers. |
| PegloOracle | Chainlink CRE consumer: rates, halts, depeg prices, feed bounds and guardian. |
| PegloBatchTaker | Fills many legs across both routers in one transaction with a minimum output and deadline. |
| PegloLens | Builds orders and reads strategy balances and spendable amounts. |
SwapVM caps instruction arguments at 255 bytes, so configs are packed. A range is n, the token addresses, their decimals, the floor (16 bytes), the edge ratio (8), the USD fee (2), the FX fee (2), the exposure cap (2) and the oracle (20): 1 + 21n + 50 bytes. A backstop swaps the range fields for the two discounts and the cap: 1 + 21n + 40 bytes. That allows 9 coins on the Peglo router and 8 through Extruction, where the target address takes 20 more bytes.
This app's deployment
No deployment is loaded in this app yet.
Networks
Solana addresses and coin mints are in the Solana chapter.
Base mainnet, 1inch and Chainlink
| Contract | Address |
|---|---|
| 1inch Aqua | 0x1111113CCf1426A8E30e2bfF5E005d929bF6a90a |
| 1inch AquaSwapVMRouter | 0x111111338c5091E8440b67B168bAe16a668AC0De |
| Chainlink CRE forwarder | 0xF8344CFd5c43616a4366C34E3EEE75af79a74482 |
| Multicall3 | 0xcA11bde05977b3631167028862bE2a173976CA11 |
Coins on Base
| Coin | Address | Decimals |
|---|---|---|
| USDC | 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 | 6 |
| USDT | 0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2 | 6 |
| DAI | 0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb | 18 |
| USDS | 0x820C137fa70C8691f0e44Dc420a5e53c168921Dc | 18 |
| USDe | 0x5d3a1Ff2b6BAb83b63cd9AD0787074081a52ef34 | 18 |
| EURC | 0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42 | 6 |
| BRZ | 0xE9185Ee218cae427aF7B9764A011bb89FeA761B4 | 18 |
| IDRX | 0x18Bc5bcC660cf2B9cE3cd51a404aFe1a0cBD3C22 | 2 |
Chainlink feeds on Base
| Feed | Address | Used for |
|---|---|---|
| EUR / USD | 0xc91D87E81faB8f93699ECf7Ee9B44D11e1D53F0F | EURC rate |
| BRL / USD | 0x0b0E64c05083FdF9ED7C5D3d8262c4216eFc9394 | BRZ rate |
| IDR / USD | 0x05A6cF213EcC5501A11a08EBefA4A8a60313ef97 | IDRX rate |
| EURC / USD | 0x9867186e52d2F1C2c565CDA6E747101Fa56501e0 | EURC depeg check |
| USDC / USD | 0x7e860098F58bBFC8648a4311b374B1D669a2bc6B | USDC depeg check |
| USDT / USD | 0xf19d560eB8d2ADf07BD6D13ed03e1D11215721F9 | USDT depeg check |
| DAI / USD | 0x591e79239a7d679378eC8c847e5038150364C78F | DAI depeg check |
| USDS / USD | 0x2330aaE3bca5F05169d5f4597964D44522F62930 | USDS depeg check |
| USDe / USD | 0x790181e93e9F4Eedb5b864860C12e4d2CffFe73B | USDe depeg check |
Base Sepolia
1inch has not deployed Aqua or the SwapVM router on Base Sepolia, so the deploy script deploys their unmodified source next to Peglo, with test coins and testnet FX feeds synced from Base mainnet Chainlink. Chainlink's CRE simulation forwarder is 0x82300bd7c3958625581cc2F77bC6464dcEcDF3e5.
SDK
@peglo/sdk (TypeScript, viem) reads the market, quotes, routes and ships. Amounts are bigints in token units; USD amounts use 18 decimals.
import { PegloClient, WAD } from '@peglo/sdk'
const client = new PegloClient(publicClient, deployment)
const market = await client.market()
const quote = client.quoteExactIn(market, USDC, EURC, 1_000_000_000n)
const { hash, amountOut } = await client.swap(wallet, quote, 30)
const range = client.buildRange('balanced', 1_000n * WAD, { tokens: [USDC, USDT, EURC] })
await client.ship(wallet, range, 1_000n * WAD, { kind: 'native' })
const backstop = client.buildBackstop(200, 1000, 20_000n * WAD)
await client.shipBackstop(wallet, backstop, pledges, { kind: 'native' })
const status = await client.oracleStatus()
await client.dock(wallet, strategy)| Method | Does |
|---|---|
market() | Every live range and backstop with balances, spendable amounts and oracle prices |
quoteExactIn(market, in, out, amount) | The best split across strategies, with each leg |
swap(wallet, quote, slippageBps) | Approves if needed and settles the quote through the batch taker |
buildRange(width, usdPerCoin, opts) | A range config for the chosen coins, width, exposure cap and oracle |
ship(wallet, config, usdPerCoin, venue) | Approves Aqua and ships the range at live prices |
buildBackstop(start, end, cap) | A backstop config over every coin |
shipBackstop(wallet, config, pledges, venue) | Approves and ships a backstop |
dock(wallet, strategy) | Closes a strategy |
oracleStatus() | CRE and guardian halt flags and the last reported price for each coin |
Run it locally
Requirements: Foundry, Node 22 or newer, Go 1.25 or newer, and the Chainlink CRE CLI.
npm install (cd contracts && npm install) FORK_PORT=8556 DEPLOYMENT_NAME=base-fork-fx ./ops/devnet.sh npm run price-api -w @peglo/ops cd app && NEXT_PUBLIC_DEV_ACCOUNTS=1 NEXT_PUBLIC_RPC_URL=http://127.0.0.1:8556 \ DEPLOYMENT_NAME=base-fork-fx npx next dev -p 3000 cd cre && cre workflow simulate depeg-sentinel -T fork-settings --broadcast \ --non-interactive --trigger-index 0 cd contracts && forge test npm test -w @peglo/sdk cd cre/depeg-sentinel && go test ./...
The fork freezes Chainlink's feeds while new blocks use the real clock, so FX swaps pause with a stale rate about 75 minutes after it starts. Restart it before a demo.
Errors
| Error | Meaning |
|---|---|
Halted | Chainlink CRE or the guardian halted this coin. Ranges refuse it; only backstops buy it. |
StaleRate | A Chainlink FX rate is too old, so ranges with that coin pause. |
RangeEdge | The range reached its edge for this coin. |
ExposureCap | The fill would push one coin past its share of the range. |
InsufficientLiquidity | The maker no longer holds or allows enough of the output coin. |
OutOfRange | The trade is larger than the range can price. |
BackstopFull | The backstop cap for this coin is used up. |
NotDepegged | Backstops only buy halted coins. |
PayoutHalted | Backstops never pay out a halted coin. |
ExactInOnly | Backstops only take exact-input trades. |
InsufficientOutput | The trade moved past your slippage limit. |
Expired | The 10 minute deadline passed. Quote again. |
ValueDecreased | The fill would shrink the LP position, so it reverts. |
UnauthorizedWorkflowOwner | A report came from a workflow that is not the set owner. |
Security model
- Funds move only inside a fill, priced by the contracts, from a maker wallet to a taker and back. No admin function can move maker coins.
- Every fill re-derives the range and reverts if the LP position would shrink.
- The oracle owner sets feeds, staleness limits, the forwarder and the workflow owner, and acts as guardian. A wrong feed could misprice FX ranges, so on mainnet the owner should be a multisig.
- Chainlink CRE reports are accepted only from the forwarder and only from the set workflow owner.
- The routers can only rescue tokens held by the router itself; in normal use they hold none.
- The contracts are not audited.
Risks and limits
- Multi-token strategies rely on SwapVM v1.0.2, where the taker picks the token pair.
- One strategy holds at most 8 coins through the official router (9 natively). More coins means more strategies, combined by routing.
- A range at its edge refuses its heaviest coin instead of trading along the boundary.
- Production CRE needs deploy access from Chainlink. Without it, FX rates come from Chainlink feeds and halts only from the guardian.
- Free price APIs rate limit. An API halt needs every API to agree, so it can be delayed while one is down; Chainlink feeds still halt alone.
- Each leg of a trade costs gas, so the router favors larger strategies. Small strategies are filled less often.
- Liquidity outside EURC is thin on Base today: BRZ and IDRX supply is small.
FAQ
Do my coins leave my wallet?
Only when a trade fills, and only the output coin of that trade, straight to the trader.
Can I spend while providing?
Yes. Fills check your live balance first and route around you if you are short.
Can I lose money?
Yes, through a coin that depegs before your edge, through currency moves if you hold EURC, BRZ or IDRX, or through a backstop buying a coin that keeps falling. A single trade can never shrink your position.
What if Chainlink CRE stops?
FX rates fall back to Chainlink feeds, ranges keep trading, and a stale feed pauses FX swaps instead of mispricing them. Halts then come only from the guardian.
Who pays gas?
Takers pay for swaps. Makers pay for approvals, ship and dock. Nobody pays to keep a strategy open.
Why at most 8 coins in one strategy?
SwapVM caps instruction arguments at 255 bytes. More coins are covered by more strategies, combined by the router.
Is there a token or a protocol fee?
No. LPs keep every fee their ranges earn.
What is Extruction?
A SwapVM instruction that calls out to another contract for pricing. It lets 1inch's official router price Peglo strategies.