Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
clean up branching logic
Browse files Browse the repository at this point in the history
  • Loading branch information
arjun-io committed Aug 1, 2023
1 parent 8371940 commit ee909cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -515,19 +515,18 @@ contract BalancedVault is IBalancedVault, BalancedVaultDefinition, UInitializabl
// so instead open 0 value instead
if (makerAvailable.isZero()) product.openMake(UFixed18Lib.ZERO);
else product.closeMake(accountPosition.sub(targetPosition).min(makerAvailable));
}

if (targetPosition.gte(accountPosition)) {
} else if (targetPosition.gt(accountPosition)) {
// compute headroom until hitting makerLimit
UFixed18 currentMaker = product.positionAtVersion(product.latestVersion()).next(product.pre()).maker;
UFixed18 makerLimit = product.makerLimit();
UFixed18 makerAvailable = makerLimit.gt(currentMaker) ? makerLimit.sub(currentMaker) : UFixed18Lib.ZERO;

// If there is no maker available (maker limit), we still need a settlement but opening 0 value will revert,
// so instead close 0 value instead
if (makerAvailable.isZero() || (targetPosition.isZero() && accountPosition.isZero()))
product.closeMake(UFixed18Lib.ZERO);
if (makerAvailable.isZero()) product.closeMake(UFixed18Lib.ZERO);
else product.openMake(targetPosition.sub(accountPosition).min(makerAvailable));
} else {
product.closeMake(UFixed18Lib.ZERO);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,17 +436,18 @@ contract SingleBalancedVault is ISingleBalancedVault, UInitializable {

if (targetPosition.lt(currentPosition))
product.closeMake(currentPosition.sub(targetPosition));
if (targetPosition.gte(currentPosition)) {
else if (targetPosition.gt(currentPosition)) {
// compute headroom until hitting makerLimit
UFixed18 currentMaker = product.positionAtVersion(product.latestVersion()).next(product.pre()).maker;
UFixed18 makerLimit = product.makerLimit();
UFixed18 makerAvailable = makerLimit.gt(currentMaker) ? makerLimit.sub(currentMaker) : UFixed18Lib.ZERO;

// If there is no maker available (maker limit), we still need a settlement but opening 0 value will revert,
// so instead close 0 value instead
if (makerAvailable.isZero() || (targetPosition.isZero() && currentPosition.isZero()))
product.closeMake(UFixed18Lib.ZERO);
if (makerAvailable.isZero()) product.closeMake(UFixed18Lib.ZERO);
else product.openMake(targetPosition.sub(currentPosition).min(makerAvailable));
} else {
product.closeMake(UFixed18Lib.ZERO);
}

emit PositionUpdated(product, targetPosition);
Expand Down

0 comments on commit ee909cd

Please sign in to comment.