Skip to content

Forked Rebalance Simulation 3d#172

Merged
jribbink merged 4 commits intofeature/forked-simulationsfrom
jribbink/fork-scenario-3d
Mar 3, 2026
Merged

Forked Rebalance Simulation 3d#172
jribbink merged 4 commits intofeature/forked-simulationsfrom
jribbink/fork-scenario-3d

Conversation

@jribbink
Copy link
Copy Markdown
Contributor

@jribbink jribbink commented Feb 13, 2026

Closes: #163

Description

Converts scenario 3d to a forked simulation.

Failing test is not related to this PR
https://github.com/onflow/FlowYieldVaults/actions/runs/22596031626/job/65466138035#step:9:1299

Test Output
10:44AM INF Using fork height chainId=flow-mainnet forkBlockID=24806fa16bae3ee6f3852c41ba413319306e2f5620133dd0a0786d228201a712 forkHeight=143292255 host=access.mainnet.nodes.onflow.org:9000
10:44AM INF LOG: "[TEST] Captured Position ID from event: 5"
10:44AM INF LOG: "[TEST] YieldVault ID: 208"
10:44AM INF LOG: "\n=== PRECISION COMPARISON (Initial State) ==="
10:44AM INF LOG: "Expected Yield Tokens: 615.38461539"
10:44AM INF LOG: "Actual Yield Tokens:   615.38461537"
10:44AM INF LOG: "Difference:            -0.00000002"
10:44AM INF LOG: ""
10:44AM INF LOG: "Expected Flow Collateral Value: 1000.00000000"
10:44AM INF LOG: "Actual Flow Collateral Value:   1000.00000000"
10:44AM INF LOG: "Difference:                     -0.00000000"
10:44AM INF LOG: ""
10:44AM INF LOG: "Expected MOET Debt: 615.38461539"
10:44AM INF LOG: "Actual MOET Debt:   615.38461538"
10:44AM INF LOG: "Difference:         -0.00000001"
10:44AM INF LOG: "=========================================================\n"
10:44AM INF LOG: "\n=== FLOW PRICE \u{2192} 0.5x ==="
10:44AM INF LOG: "\n=== PRECISION COMPARISON (After Flow Price Decrease) ==="
10:44AM INF LOG: "Expected Yield Tokens: 307.69230769"
10:44AM INF LOG: "Actual Yield Tokens:   307.69230767"
10:44AM INF LOG: "Difference:            -0.00000002"
10:44AM INF LOG: ""
10:44AM INF LOG: "Expected Flow Collateral Value: 500.00000000"
10:44AM INF LOG: "Actual Flow Collateral Value:   500.00000000"
10:44AM INF LOG: "Actual Flow Collateral Amount:  1000.00000000 Flow tokens"
10:44AM INF LOG: "Difference:                     -0.00000000"
10:44AM INF LOG: ""
10:44AM INF LOG: "Expected MOET Debt: 307.69230769"
10:44AM INF LOG: "Actual MOET Debt:   307.69230769"
10:44AM INF LOG: "Difference:         -0.00000000"
10:44AM INF LOG: "=========================================================\n"
10:44AM INF LOG: "\n=== YIELD VAULT PRICE \u{2192} 1.5x ==="
10:44AM INF LOG: "\n=== PRECISION COMPARISON (After Yield Price Increase) ==="
10:44AM INF LOG: "Expected Yield Tokens: 268.24457594"
10:44AM INF LOG: "Actual Yield Tokens:   268.24457535"
10:44AM INF LOG: "Difference:            -0.00000059"
10:44AM INF LOG: ""
10:44AM INF LOG: "Expected Flow Collateral Value: 653.84615385"
10:44AM INF LOG: "Actual Flow Collateral Value:   653.84615245"
10:44AM INF LOG: "Actual Flow Collateral Amount:  1307.69230491 Flow tokens"
10:44AM INF LOG: "Difference:                     -0.00000140"
10:44AM INF LOG: ""
10:44AM INF LOG: "Expected MOET Debt: 402.36686391"
10:44AM INF LOG: "Actual MOET Debt:   402.36686304"
10:44AM INF LOG: "Difference:         -0.00000087"
10:44AM INF LOG: "=========================================================\n"
10:44AM INF LOG: "\n=== TEST COMPLETE ==="
______

For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@jribbink jribbink force-pushed the jribbink/fork-scenario-3d branch from d9f1702 to eef42c2 Compare February 24, 2026 16:40
@jribbink jribbink changed the base branch from jribbink/fork-scenario-3c to jribbink/evm-test-helpers February 24, 2026 16:40
@jribbink jribbink force-pushed the jribbink/fork-scenario-3d branch from eef42c2 to 6369838 Compare February 24, 2026 16:50
Base automatically changed from jribbink/evm-test-helpers to feature/forked-simulations February 25, 2026 18:00
@jribbink jribbink force-pushed the jribbink/fork-scenario-3d branch from 8009611 to 34e65b4 Compare February 25, 2026 18:06
@jribbink jribbink linked an issue Feb 25, 2026 that may be closed by this pull request
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@jribbink jribbink force-pushed the jribbink/fork-scenario-3d branch from 82b2cd4 to 7e17711 Compare March 2, 2026 18:50
@jribbink jribbink changed the title [WIP] Forked Rebalance Simulation 3d Forked Rebalance Simulation 3d Mar 2, 2026
@jribbink jribbink marked this pull request as ready for review March 2, 2026 19:06
@jribbink jribbink requested a review from a team as a code owner March 2, 2026 19:06
@jribbink jribbink requested a review from RZhang05 March 2, 2026 21:56
Copy link
Copy Markdown
Contributor

@RZhang05 RZhang05 left a comment

Choose a reason for hiding this comment

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

Any experience locally with inconsistent runs? First run did not trigger rebalance, this happens with scenario 3a and 3b as well. Mainly wondering if these tests could fail in CI.

Output
flow test cadence/tests/forked_rebalance_scenario3d_test.cdc 

❗   Version warning: a new version of Flow CLI is available (v2.14.3).
   Read the installation guide for upgrade instructions: https://developers.flow.com/tools/flow-cli/install 

11:42AM INF Using fork height chainId=flow-mainnet forkBlockID=24806fa16bae3ee6f3852c41ba413319306e2f5620133dd0a0786d228201a712 forkHeight=143292255 host=access.mainnet.nodes.onflow.org:9000
11:42AM INF LOG: "[TEST] Captured Position ID from event: 5"
11:42AM INF LOG: "[TEST] YieldVault ID: 208"
11:42AM INF LOG: "\n=== PRECISION COMPARISON (Initial State) ==="
11:42AM INF LOG: "Expected Yield Tokens: 615.38461539"
11:42AM INF LOG: "Actual Yield Tokens:   615.38461537"
11:42AM INF LOG: "Difference:            -0.00000002"
11:42AM INF LOG: ""
11:42AM INF LOG: "Expected Flow Collateral Value: 1000.00000000"
11:42AM INF LOG: "Actual Flow Collateral Value:   1000.00000000"
11:42AM INF LOG: "Difference:                     -0.00000000"
11:42AM INF LOG: ""
11:42AM INF LOG: "Expected MOET Debt: 615.38461539"
11:42AM INF LOG: "Actual MOET Debt:   615.38461538"
11:42AM INF LOG: "Difference:         -0.00000001"
11:42AM INF LOG: "=========================================================\n"
11:42AM INF LOG: "\n=== FLOW PRICE \u{2192} 0.5x ==="
11:42AM INF LOG: "\n=== PRECISION COMPARISON (After Flow Price Decrease) ==="
11:42AM INF LOG: "Expected Yield Tokens: 307.69230769"
11:42AM INF LOG: "Actual Yield Tokens:   615.38461537"
11:42AM INF LOG: "Difference:            +307.69230768"
11:42AM INF LOG: ""
11:42AM INF LOG: "Expected Flow Collateral Value: 500.00000000"
11:42AM INF LOG: "Actual Flow Collateral Value:   500.00000000"
11:42AM INF LOG: "Actual Flow Collateral Amount:  1000.00000000 Flow tokens"
11:42AM INF LOG: "Difference:                     -0.00000000"
11:42AM INF LOG: ""
11:42AM INF LOG: "Expected MOET Debt: 307.69230769"
11:42AM INF LOG: "Actual MOET Debt:   615.38461538"
11:42AM INF LOG: "Difference:         +307.69230769"
11:42AM INF LOG: "=========================================================\n"

Test results: "cadence/tests/forked_rebalance_scenario3d_test.cdc"
- FAIL: test_ForkedRebalanceYieldVaultScenario3D
                Execution failed:
                        error: assertion failed: Expected yield tokens after flow price decrease to be 307.69230769 but got 615.38461537
                           --> cadence/tests/forked_rebalance_scenario3d_test.cdc:281:4

@jribbink
Copy link
Copy Markdown
Contributor Author

jribbink commented Mar 3, 2026

Any experience locally with inconsistent runs? First run did not trigger rebalance, this happens with scenario 3a and 3b as well. Mainly wondering if these tests could fail in CI.

Output

No, I hadn't seen that, but I was able to reproduce.... very strange 🤔, the only things that I can think of that could cause this non-determinism would be randomness or a bug in the testing framework/runtime...

EDIT: Thinking about this more, it could be a race condition with timestamps in the testing framework. I.e. the Band Oracle update relies on the current timestamp. If this does not advance between updates, subsequent updates may not be reflected here.

@jribbink
Copy link
Copy Markdown
Contributor Author

jribbink commented Mar 3, 2026

Yeah, Band Oracle was the cause - fixed in 2338365

@jribbink jribbink merged commit 734e435 into feature/forked-simulations Mar 3, 2026
2 of 5 checks passed
@jribbink jribbink deleted the jribbink/fork-scenario-3d branch March 3, 2026 19:33
jribbink added a commit that referenced this pull request Apr 3, 2026
* Recreate scenario 1 using forked testnet.

* Remove unused function.

* Update for mainnet addresses.

* Use mUSDC strategy with real oracles on testnet.

* Update symbol prices.

* Switch to mainnet.

* Add option to transfer flow from whale account instead of minting.

* Use fixed mainnet height, new FUSDEV strategy.

* Add percent tolerance check to forked test.

* Clean up forked scenario 1.

* Remove unnecessary imports.

* Create forked scenario 2 with placeholder yield token function.

* [WIP] Modify EVM storage in forked scen2. Currently fails tolerance.

* Add EVM State Manipulation Helpers For Forked Simulations

* Clean up.

* Prepare for updated strategy.

* Fix bugs with decimal offsets & cleanup

* tidy comments

* Cleanup test helpers & fix precision

* Account for fees in pool prices to stay in tolerance.

* Update to newer CLI

* Create forked scenario 3a, 3b.

* address feedback

* Add test for EVM state helpers

* cleanup test assertion

* cleanup test assertion

* Fix percent tolerance

* Run CI on feature/* branches

* Update to new strategy and use new evm helpers.

* Clean up.

* Add EVM State Manipulation Helpers For Forked Simulations (#173)

* Fix band oracle price helper (#188)

* Fix merge.

* Normalize comments.

* Temporarily skip closing of yield vault.

* Apply suggestions from code review

Co-authored-by: Jordan Ribbink <17958158+jribbink@users.noreply.github.com>

* Switch flow.json back to tab spacing.

* Fix scenario 2.

* Delete unused files.

* Improve precision of forked tests

* Improve precision of forked tests (#190)

* Update scenario 2.

* Improve scenario 2 fee accounting and tolerance.

* Update forked scen 3a, 3b.

* Fix fork height.

* Add CI Caching for Forked Mainnet Simulation Tests (#192)

* Apply suggestions from code review

Co-authored-by: Jordan Ribbink <17958158+jribbink@users.noreply.github.com>

* Add Forked Mainnet Simulation Scenario 3C (#169)

* Improve final diagnostic precision.

* Forked Rebalance Simulation 3d (#172)

* Update Flow CLI Install to use Latest Version (#213)

* Add forked rebalance scenario 4. (#196)

* Add forked rebalance scenarios 4 and 5.

* Update forked scenarios to match main.

* Update scenarios 4,5.

* add boundary test cases

* Update fork test block height

* Remove unused Test.reset

* Restore commented out sections

* Apply suggestion from @zhangchiqing

Co-authored-by: Leo Zhang <zhangchiqing@gmail.com>

* Remove unnecessary yield vault rebalances

* Add note about Google Sheet

* Update cadence/tests/forked_rebalance_scenario1_test.cdc

Co-authored-by: Leo Zhang <zhangchiqing@gmail.com>

* add comments and more assertion on forked rebalance tests

* add more assertion and comments to forked_rebalance_scenario2_test.cdc

---------

Co-authored-by: Raymond Zhang <zhangraymond05@gmail.com>
Co-authored-by: Leo Zhang (zhangchiqing) <zhangchiqing@gmail.com>
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.

Recreate Simulation Scenario 3d With Fork Testing Setup

2 participants