diff --git a/packages/perennial-vaults/contracts/balanced/BalancedVault.sol b/packages/perennial-vaults/contracts/balanced/BalancedVault.sol index b4df9690..1f091f3e 100644 --- a/packages/perennial-vaults/contracts/balanced/BalancedVault.sol +++ b/packages/perennial-vaults/contracts/balanced/BalancedVault.sol @@ -515,9 +515,7 @@ 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(); @@ -525,9 +523,10 @@ contract BalancedVault is IBalancedVault, BalancedVaultDefinition, UInitializabl // 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); } } diff --git a/packages/perennial-vaults/contracts/single-balanced/SingleBalancedVault.sol b/packages/perennial-vaults/contracts/single-balanced/SingleBalancedVault.sol index 7f30ce1b..820c485b 100644 --- a/packages/perennial-vaults/contracts/single-balanced/SingleBalancedVault.sol +++ b/packages/perennial-vaults/contracts/single-balanced/SingleBalancedVault.sol @@ -436,7 +436,7 @@ 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(); @@ -444,9 +444,10 @@ contract SingleBalancedVault is ISingleBalancedVault, UInitializable { // 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);