Skip to content

[Task] Withdrawal buffer for OS Vault - #2649

Merged
naddison36 merged 2 commits into
masterfrom
clement/Withdrawal-buffer-for-OS-Vault
Sep 3, 2025
Merged

[Task] Withdrawal buffer for OS Vault#2649
naddison36 merged 2 commits into
masterfrom
clement/Withdrawal-buffer-for-OS-Vault

Conversation

@clement-ux

@clement-ux clement-ux commented Sep 2, 2025

Copy link
Copy Markdown
Collaborator

This pull request introduces a buffer mechanism to the undelegation logic in sonicActions.js so the OS ARM can convert its purchased OS back to wS quicker, the OS Vault will undelegate a small percentage each day. The main changes are:

Vault withdrawal logic update:

  • Added a buffer calculation (0.01% of vault's total assets) to ensure that a portion of the assets is reserved and not immediately available for undelegation. The available balance for undelegation is now reduced by this buffer.

Transaction handling:

  • Commented out the actual undelegate transaction call, possibly for debugging or to prevent execution during testing, while retaining the logging of transaction details.

Testing

Start a local Sonic fork

# Set SONIC_PROVIDER_URL in .env file or export it
export SONIC_PROVIDER_URL=
yarn run node:sonic
# Set IMPERSONATE in .env file or export it
export IMPERSONATE=0x531B8D5eD6db72A56cF1238D4cE478E7cB7f2825
FORK=true npx hardhat sonicUndelegate --network localhost

Results from a local test

FORK=true npx hardhat sonicUndelegate --network localhost --buffer 100
  origin:utils:signers Impersonating account 0x531B8D5eD6db72A56cF1238D4cE478E7cB7f2825 from IMPERSONATE environment variable +0ms
  origin:utils:signers Impersonating account 0x531B8D5eD6db72A56cF1238D4cE478E7cB7f2825 +1ms
  origin:utils:signers Funding account 0x531B8D5eD6db72A56cF1238D4cE478E7cB7f2825 with 100 ETH +105ms
  origin:task:sonic wS balance in vault           : 607705.025171298185245333 wS +0ms
  origin:task:sonic Unclaimed vault withdrawals   : 504969.170175302148824723 wS +143ms
  origin:task:sonic Available wS in vault         : 102735.85499599603642061 wS +0ms
  origin:task:sonic Pending validator withdrawals : 68315.404903981938878939 wS +19ms
  origin:task:sonic wS with validator withdrawals : 171051.259899977975299549 wS +0ms
  origin:task:sonic Total vault assets            : 34210251.979995595059909886 wS +87ms
  origin:task:sonic Buffer (1% of total assets) : 342102.519799955950599098 wS +1ms
  origin:task:sonic wS target with buffer         : -171051.259899977975299549 wS +1ms
  origin:task:sonic About to undelegate 171051.259899977975299549 S from validator 18 +9ms
  origin:utils:txLogger Sent undelegate transaction with hash 0xab9bec41793fbd7d9ae3cac2539261b2a13d24dcfec8b766fd4d448bd78f35bf from 0x531B8D5eD6db72A56cF1238D4cE478E7cB7f2825 with gas price 1 Gwei +0ms
  origin:utils:txLogger Processed undelegate tx in block 45545459, using 269132 gas costing 0.000269132 ETH +8ms

Deployment

cd ./scripts/defender-actions
npx rollup -c

export API_KEY=
export API_SECRET=

npx defender-autotask update-code 84988850-6816-4074-8e7b-c11cb2b32e7e ./dist/sonicRequestWithdrawal

@clement-ux
clement-ux marked this pull request as draft September 2, 2025 18:25
@codecov

codecov Bot commented Sep 2, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 38.24%. Comparing base (d5fd2cd) to head (bc77c7b).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2649      +/-   ##
==========================================
- Coverage   38.26%   38.24%   -0.02%     
==========================================
  Files         112      112              
  Lines        5331     5331              
  Branches     1412     1412              
==========================================
- Hits         2040     2039       -1     
- Misses       3289     3290       +1     
  Partials        2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Set vault buffer to 0.5% for undelegating S from the validator

@naddison36 naddison36 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this

@naddison36
naddison36 marked this pull request as ready for review September 3, 2025 00:36
@naddison36
naddison36 merged commit 6a6d164 into master Sep 3, 2025
17 of 21 checks passed
@naddison36
naddison36 deleted the clement/Withdrawal-buffer-for-OS-Vault branch September 3, 2025 00:55
@notion-workspace

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants