Skip to content
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

Autoreset flows #3

Closed
wants to merge 0 commits into from
Closed

Conversation

adhusson
Copy link
Contributor

@adhusson adhusson commented Feb 12, 2024

Autoreset flows on update following @MathisGD's suggestion. Pros: code is simpler, one less parameter (removed resetFlow). Con: tracking flow imbalance is much harder.

For later, snippet to update flow caps without resetting the imbalance (given reference flow caps):

function updateCapsWithoutResetSnippet(FlowCaps memory oldReferenceCaps, FlowCaps memory newReferenceCaps,Id marketId) internal view returns (FlowCaps memory newCaps) {
    FlowCaps memory currentCaps = IPublicAllocator(publicAllocator).flowCaps(marketId);
    if (oldReferenceCaps.maxIn > currentCaps.maxIn) {
        newCaps.maxIn = newReferenceCaps.maxIn - (oldReferenceCaps.maxIn - currentCaps.maxIn);
    } else {
        newCaps.maxIn = newReferenceCaps.maxIn + (currentCaps.maxIn - oldReferenceCaps.maxIn);
    }

    if (oldReferenceCaps.maxOut > currentCaps.maxOut) {
        newCaps.maxOut = newReferenceCaps.maxOut - (oldReferenceCaps.maxOut - currentCaps.maxOut);
    } else {
        newCaps.maxOut = newReferenceCaps.maxOut + (currentCaps.maxOut - oldReferenceCaps.maxOut);
    }

}

@adhusson adhusson requested a review from MathisGD February 12, 2024 15:27
@adhusson adhusson changed the title Feat/autoreset flows Autoreset flows Feb 12, 2024
@adhusson adhusson force-pushed the feat/autoreset-flows branch 2 times, most recently from e1ddbe9 to faf5628 Compare February 13, 2024 12:39
@adhusson adhusson closed this Feb 13, 2024
@adhusson adhusson force-pushed the feat/autoreset-flows branch from e64620b to 7bea44b Compare February 13, 2024 13:06
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.

1 participant