-
Notifications
You must be signed in to change notification settings - Fork 2
osToken redemptions #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ulieth
wants to merge
8
commits into
main
Choose a base branch
from
redemptions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
osToken redemptions #106
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
de0542b
osToken redemptions
ulieth 28104e9
fix broken links
ulieth 94a9c78
fixed inaccuracies and added a new visual
ulieth 4d1d1ad
fix hyperlink targets
ulieth 716b694
fix hyperlink targets for redemption and liquidation
ulieth 65be5fa
removed file extension suffixe from the name
ulieth e3333e7
fix color reference
ulieth 47c9e9a
fix alt description
ulieth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,19 @@ | ||
| --- | ||
| title: osToken | ||
| description: Learn what osToken is and how to get it | ||
| description: osToken is StakeWise's liquid, overcollateralized staking token on Ethereum and Gnosis. | ||
| --- | ||
|
|
||
| import Image from '@theme/IdealImage' | ||
|
|
||
| # osToken | ||
|
|
||
| osToken is a liquid staking token that accrues staking rewards when held. It is a generic name for StakeWise's network-specific ERC-20 tokens: | ||
| Staked ETH and GNO earn rewards, but the stake itself is a non-transferable share of the staking pool. osToken turns that stake into a transferable asset that can be [used across DeFi](https://app.stakewise.io/ecosystem) to earn additional rewards. | ||
|
|
||
| osToken is the generic name for StakeWise's network-specific liquid staking ERC-20 tokens: | ||
|
|
||
| - **osETH** on Ethereum | ||
| - **osGNO** on Gnosis Chain | ||
|
|
||
| <Image img={require('./img/osToken_intro.png')} alt="osToken overview - liquid staking token for StakeWise" /> | ||
|
|
||
| osToken is issued against assets staked in a Vault to allow using staked capital in decentralized applications to trade, borrow, lend, and restake. Hence, osTokens represent the underlying staked assets and the rewards earned. | ||
| osToken is overcollateralized: more ETH or GNO is always staked than osToken issued. osToken is a repricing token: it accrues staking rewards by appreciating against the underlying asset, rather than increasing the token balance in the user's wallet. | ||
|
|
||
| Short for **Overcollateralized Staked Token**, osToken requires that the value of staked assets exceed the value of osToken issued. This overcollateralization acts as a safety buffer, protecting holders and the protocol from validator penalties or underperformance of permissionless Vaults. | ||
|
|
||
| A defining feature is that osToken can be minted against validators run by anyone – from solo stakers to professional operators – making access to liquid staking fully permissionless and non-custodial. | ||
| <Image img={require('./img/osToken_intro.png')} alt="osToken overview - liquid staking token for StakeWise" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| --- | ||
| title: osToken Redemptions | ||
| description: How osToken redemptions work under the hood. | ||
| --- | ||
|
|
||
| import Admonition from '@theme/Admonition'; | ||
| import Image from '@theme/IdealImage'; | ||
|
|
||
| # osToken Redemptions | ||
|
|
||
| Redemptions are a protocol-internal peg-maintenance mechanism that converts osToken back to ETH/GNO at the protocol exchange rate. | ||
|
|
||
| Every osToken is minted against Vault collateral and must remain backed by that collateral. The minter takes on a corresponding debt against their Vault collateral and can burn the osToken at any time to repay the debt. The protocol's invariant is **total osToken supply = total debt**. | ||
|
|
||
| If the minter transfers the osToken away, the minter's on-chain debt is unchanged. From the protocol's perspective: the minter owes `X` osToken worth of debt, but only `Y < X` is still in their hands. The delta `X − Y` is what the protocol calls **redeemable** — osToken that exists somewhere but is no longer tied to a minter. | ||
|
|
||
| Redemption burns the missing portion of the minter's debt against their collateral and releases the corresponding ETH/GNO at the protocol exchange rate. | ||
|
|
||
| ## How Redemptions Work | ||
|
|
||
| <Image img={require('./img/redemptions.png')} alt="redemptions flow" /> | ||
|
|
||
| The redemption flow is a coordinated process between the [Operator Service ↗](https://github.com/stakewise/v3-operator) and the [OsTokenRedeemer ↗](https://etherscan.io/address/0xc43A7b16A7a167c0318390Cba16787C11e9e1FD0) contract. | ||
|
|
||
| The Operator Service has two responsibilities: | ||
|
|
||
| 1. **Computes redeemable positions** — the "who can be redeemed, and by how much" calculation. It uploads the list of eligible positions to [IPFS](https://ipfs.stakewise.io/ipfs/bafkreihbwhyaqskcczhuanu2nbdgdlfbwfwgbirue6kvlw4nrc5d2snqxa) and computes a Merkle tree that commits to each entry. StakeWise then submits the root and IPFS hash on-chain, incrementing the `nonce` — a version tag baked into every entry of the list, so bumping it automatically invalidates every proof from the previous version. | ||
|
|
||
| 2. **Processes redemptions** — runs a loop that reads and writes to `OsTokenRedeemer`. When the redemption conditions are met, it fetches all positions from IPFS, decides how much to redeem from each position, builds a Merkle multi-proof, and submits a multicall that refreshes Vault state and calls `redeemOsTokenPositions`. The Operator Service runs from the `positionsManager` address set by StakeWise. | ||
|
|
||
| The `OsTokenRedeemer` is the on-chain contract that holds all redemption state: the published Merkle root and IPFS hash, the nonce, per-position redemption progress, and the exit queue. It also executes the redemption itself: verifies the Merkle proofs, calls each Vault's `redeemOsToken` to burn the minter's debt and release the corresponding ETH/GNO, and manages the exit queue. | ||
|
|
||
| :::custom-notes[Under the Hood] | ||
| **The Operator Service computes the redeemable positions in five steps**: | ||
|
|
||
| 1. Pin the snapshot to a finalized block so all the following steps read the same on-chain state. | ||
| 2. Fetch all allocators (addresses that have minted osToken) from the subgraph. | ||
| 3. Skip [Boost](../vaults/boost) positions. Each Boost leverage position has its own proxy contract that holds the osToken on the user's behalf, so those proxy addresses are removed from the minters list, and each user's leveraged shares are subtracted from their balance to avoid double-counting. | ||
| 4. Compute `kept` shares — osToken in trackable locations: mainnet, Arbitrum, and DeFi protocols indexed by DeBank or Rabby. Anything else is treated as missing. | ||
| 5. Compute `redeemable = minted − kept`, split it across the user's vaults proportionally to where they minted, and sort by LTV descending then amount descending so the riskiest positions are drawn down first. | ||
| ::: | ||
|
|
||
| ## Flow | ||
| ### 1. osToken Enters the Queue | ||
|
|
||
| osToken is sent to the `OsTokenRedeemer` contract and a ticket is issued — a unique cumulative index recording the entry's place in the queue and how much is owed. The entry now carries the right to claim ETH/GNO later. | ||
|
|
||
| ### 2. Operator Service Prepares the Next Redemption | ||
|
|
||
| The Operator Service monitors the on-chain state. If a previous redemption round has redeemed ETH/GNO waiting to be checkpointed, it first calls `processExitQueue` to finalize that batch so the assets become claimable. | ||
|
|
||
| It then checks whether there's enough queued osToken to submit a new redemption. | ||
|
|
||
| ### 3. Operator Service Submits a Redemption | ||
|
|
||
| The Operator Service downloads the published list from IPFS, picks a batch of eligible positions, and decides how much to redeem from each. If a target Vault is a MetaVault without enough liquidity on hand, the Operator Service first pulls assets up from sub-vaults via a separate `redeemSubVaultsAssets` transaction. It then builds a Merkle multiproof against the published root and submits a multicall to `OsTokenRedeemer` that refreshes Vault state and calls `redeemOsTokenPositions`. | ||
|
|
||
| The redemption is now in flight; verification and execution happen on-chain. | ||
|
|
||
| ### 4. OsTokenRedeemer Executes the Redemption | ||
|
|
||
| The contract rebuilds each leaf, verifies the Merkle multiproof against the stored root, and caps the amount independently per position. | ||
| For each verified position, it calls the Vault's `redeemOsToken` to burn the minter's osToken debt and send the equivalent ETH (using the Vault's just-updated state) to the redeemer. | ||
|
|
||
| The queued shares are now matched against missing positions — settled, but not yet claimable. | ||
|
|
||
| ### 5. Batch Is Checkpointed | ||
|
|
||
| Once the configured delay has elapsed, `processExitQueue` is called and the contract creates a new checkpoint that matches the redeemed shares to their ETH/GNO and marks the assets as claimable. Tickets that fall within this checkpoint can now be claimed. | ||
|
|
||
| :::custom-notes[Dive Deeper: The Exit Queue and Checkpoints] | ||
|
|
||
| **The queue** | ||
|
|
||
| **Note:** This is the `OsTokenRedeemer`'s own exit queue, independent of the Vault exit queue. | ||
|
|
||
| When osToken enters the queue, the assets aren't released right away. The contract tracks this line with a single number, the `positionTicket`: | ||
|
|
||
| `positionTicket = (all previously processed shares) + (shares already queued ahead)` | ||
|
|
||
| The queue drains as the contract processes redemptions, moving shares from *queued* to *redeemed*. Redeemed shares are matched with ETH/GNO but can't be claimed yet — that requires a checkpoint. | ||
|
|
||
| **Checkpoints** | ||
|
|
||
| A checkpoint is a snapshot that says: *"at this point in the queue, this many shares were exchanged for this many assets."* When a ticket is claimed, the checkpoint covering it tells the contract: | ||
|
|
||
| - how many of its tickets are now exited (covered by the checkpoint), | ||
| - and how many assets those tickets are worth, at the rate the checkpoint locked in. | ||
|
|
||
| If only some of the ticket is covered and the rest is still queued, the contract pays out the covered portion and rolls the remainder into a new exit request at the next ticket. The rest can be claimed after the next checkpoint. | ||
| ::: | ||
|
|
||
| ### 6. ETH/GNO Is Claimed | ||
|
|
||
| `claimExitedAssets` is called with the ticket and the matching checkpoint index. The contract pays out the corresponding ETH/GNO; if the ticket spans more than one checkpoint, a residual is left for future rounds. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.