-
Notifications
You must be signed in to change notification settings - Fork 21
Reserve redemption assets #724
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
Draft
evgeny-stakewise
wants to merge
3
commits into
v5-release
Choose a base branch
from
reserve-redemption-assets-2
base: v5-release
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.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,34 +28,47 @@ async def get_redemption_assets(chain_head: ChainHead) -> Wei: | |
| Get redemption assets for operator's vault. | ||
| For Gno networks return value in GNO-Wei. | ||
| """ | ||
| # The contract increments nonce during setRedeemablePositions, | ||
| # but uses nonce - 1 for leaf hash computation during redemption. | ||
| vault_to_redemption_assets = await get_vault_to_redemption_assets_distributed(chain_head) | ||
| return vault_to_redemption_assets[settings.vault] | ||
|
|
||
|
|
||
| async def get_vault_to_redemption_assets_distributed( | ||
| chain_head: ChainHead, | ||
| ) -> defaultdict[ChecksumAddress, Wei]: | ||
| """ | ||
| Get per-vault redemption assets after distributing meta vault assets | ||
| across their entire sub-vault tree. Contains leaf vaults, root meta vaults, | ||
| and all intermediary meta sub-vaults. | ||
|
|
||
| For Gno networks values are in GNO-Wei. | ||
| """ | ||
| nonce = await os_token_redeemer_contract.nonce(chain_head.block_number) | ||
| if nonce == 0: | ||
| logger.info('Zero nonce for redemption. Skipping redemption assets.') | ||
| return Wei(0) | ||
| logger.debug('Zero nonce for redemption. Skipping redemption assets.') | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to |
||
| return defaultdict(lambda: Wei(0)) | ||
|
|
||
| protocol_config = await get_protocol_config() | ||
|
|
||
| # Aggregate redemption assets per vault | ||
| vault_to_redemption_assets = await get_vault_to_redemption_assets( | ||
| # The contract increments the nonce at the end of setRedeemablePositions, | ||
| # so use the previous nonce for leaf hash computation. | ||
| vault_to_redemption_assets = await get_vault_to_redemption_assets_direct( | ||
| chain_head=chain_head, tree_nonce=nonce - 1, protocol_config=protocol_config | ||
| ) | ||
| # Distribute redemption assets from meta vaults to their underlying vaults | ||
| vault_to_redemption_assets = await distribute_meta_vault_redemption_assets( | ||
| return await distribute_meta_vault_redemption_assets( | ||
| vault_to_redemption_assets=vault_to_redemption_assets, | ||
| block_number=chain_head.block_number, | ||
| ) | ||
| # Filter by operator's vault | ||
| return vault_to_redemption_assets[settings.vault] | ||
|
|
||
|
|
||
| async def get_vault_to_redemption_assets( | ||
| async def get_vault_to_redemption_assets_direct( | ||
| chain_head: ChainHead, tree_nonce: int, protocol_config: ProtocolConfig | ||
| ) -> defaultdict[ChecksumAddress, Wei]: | ||
| """ | ||
| Get redemption assets per vault. | ||
| For Gno networks return value in GNO-Wei. | ||
| Get redemption assets per vault, based only on assets directly assigned | ||
| to each vault in the IPFS redeemable positions file. Meta vault assets are | ||
| not yet distributed across their sub-vault tree. | ||
|
|
||
| For Gno networks return value is in GNO-Wei. | ||
| """ | ||
| ticket = await os_token_redeemer_contract.get_exit_queue_cumulative_tickets( | ||
| block_number=chain_head.block_number | ||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of rework in this file.
Previously:
distribute_meta_vault_redemption_assetsget_meta_vault_redemption_assetslooked similar. Separation of concerns was unclear.
Now:
distribute_meta_vault_redemption_assets- does the main job of distributing assets deeplyget_sub_vaults_redemptions- distributes from meta vault to direct sub vaults