Repository navigation
Conversation
The collection's withdrawUnstakedTokens / withdrawRewardedTokens return Void — they deposit the withdrawn tokens into the collection's own Cadence vault. A caller that must route the funds elsewhere (e.g. bridging them to an EVM account, as Flow's EVM-side staking control needs) has no way to receive them. This adds withdrawUnstakedTokensAsVault / withdrawRewardedTokensAsVault, which return the vault to the caller instead. They mirror the existing functions' bookkeeping — unlockedTokensUsed, including the same 'cannot return more than is in use for staking' guard that depositTokens has — and are restricted to collections WITHOUT a locked account: for a locked-token collection the withdrawn funds belong back in the locked account, so returning a vault to an arbitrary caller would bypass the lock. Locked collections keep using the existing functions. Additive only: no new fields, so no storage migration — existing collections in user storage are unaffected. Ships as a flow-core-contracts release plus a service-account contract update. Adds both transaction templates (SCO.18/SCO.19, appended after SCO.17), regenerates the Go assets/manifests, and adds a test asserting both variants revert on a collection with a locked account.
Kay-Zee
force-pushed
the
feat/staking-collection-withdraw-returns-vault
branch
from
November 24, 2026 22:28
02917df to
ad1e6b9
Compare
jribbink
reviewed
Nov 25, 2026
| }) | ||
| }) | ||
|
|
||
| t.Run("Should not be able to withdraw AsVault from a collection with a locked account", func(t *testing.T) { |
There was a problem hiding this comment.
Maybe worth adding a happy-path test for the new …AsVault functions?
| let delegator = self.borrowDelegator(nodeID: nodeID, delegatorID: delegatorID) | ||
| ?? panic("FlowStakingCollection.StakingCollection.withdrawUnstakedTokensAsVault: delegator does not exist in the collection") | ||
| let tokens <- delegator.withdrawUnstakedTokens(amount: amount) | ||
| assert( |
There was a problem hiding this comment.
Is the bookkeeping here needed? With lockedVault == nil, lockedTokensUsed is always 0 and the rewards add/sub nets out.
jribbink
approved these changes
Nov 25, 2026
vishalchangrani
approved these changes
Nov 25, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
withdrawUnstakedTokens/withdrawRewardedTokensreturn Void — theydepositTokensthe withdrawn FLOW into the collection's own Cadence vault:The underlying
FlowIDTableStaking.NodeStaker.withdrawUnstakedTokensalready returns a vault. So a caller that must route the withdrawn funds somewhere other than the collection's Cadence vault — e.g. bridging them to an EVM account — has no way to receive them. This came up building EVM-side staking control, where a registered EVM EOA takes custody of withdrawn funds and the wrapper must bridge the vault to that address.What
Two additive functions that return the vault to the caller instead — both halves of the pair, plus both transaction templates:
They mirror the existing functions' bookkeeping —
unlockedTokensUsed, including the samecannot return more FLOW than is in use for stakingguard thatdepositTokenshas (without it, withdrawing unstaked tokens that originated as rewards underflowsunlockedTokensUsed).Restricted to collections without a locked account. For a locked-token collection the withdrawn funds belong back in the locked account, so returning a vault to an arbitrary caller would bypass the lock (
depositTokensis what splits locked vs unlocked). Locked collections keep using the existing functions. Enforced by a precondition with a clear message.Compatibility
Additive only — no new fields, so no storage migration, and existing collections in user storage are unaffected. Ships as a flow-core-contracts release plus a service-account contract update.
Tests
TestStakingCollectionStakeTokens: bothAsVaultvariants revert on josh's locked-backed collection (asserts the guard). Passes.TestStakingCollection*suite passes, and the regenerated Go assets are verified to embed both functions and the guards.AsVaultcall on an unlocked collection with unstaked tokens, asserting the balance delta) still needs an unlocked-collection-with-node fixture — the existing fixtures are locked-token based (registerStakingCollectionNodesAndDelegators). Happy to add it, or to change the naming/semantics if you'd prefer a different shape.Also adds both transaction templates (
SCO.18/SCO.19, appended afterSCO.17so no existing id moves) and regenerates the assets/manifests.