diff --git a/packages/ethereum-contracts/contracts/agreements/ConstantFlowAgreementV1.sol b/packages/ethereum-contracts/contracts/agreements/ConstantFlowAgreementV1.sol index ce24f40091..8ff40facd2 100644 --- a/packages/ethereum-contracts/contracts/agreements/ConstantFlowAgreementV1.sol +++ b/packages/ethereum-contracts/contracts/agreements/ConstantFlowAgreementV1.sol @@ -1380,10 +1380,18 @@ contract ConstantFlowAgreementV1 is // calc depositDelta and newDeposit with minimum deposit rule applied if (newDeposit < minimumDeposit && flowParams.flowRate > 0) { - depositDelta = minimumDeposit.toInt256() - - oldFlowData.deposit.toInt256() - + oldFlowData.owedDeposit.toInt256(); - newDeposit = minimumDeposit; + if (flowParams.flowRate > oldFlowData.flowRate) { + // only if the flowrate increases, do we allow to increase the deposit + depositDelta = minimumDeposit.toInt256() + - oldFlowData.deposit.toInt256() + + oldFlowData.owedDeposit.toInt256(); + newDeposit = minimumDeposit; + } else { + // otherwise we keep the deposit unchanged + newDeposit = oldFlowData.deposit; + depositDelta = 0; + // TODO: what about appCreditBase ? + } } // credit should be of the same token diff --git a/packages/ethereum-contracts/contracts/agreements/gdav1/GeneralDistributionAgreementV1.sol b/packages/ethereum-contracts/contracts/agreements/gdav1/GeneralDistributionAgreementV1.sol index 1f7f32f5ee..935007ba42 100644 --- a/packages/ethereum-contracts/contracts/agreements/gdav1/GeneralDistributionAgreementV1.sol +++ b/packages/ethereum-contracts/contracts/agreements/gdav1/GeneralDistributionAgreementV1.sol @@ -503,7 +503,8 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi } { - _adjustBuffer(token, address(pool), from, flowVars.distributionFlowHash, actualFlowRate); + _adjustBuffer(token, address(pool), from, flowVars.distributionFlowHash, + flowVars.oldFlowRate, actualFlowRate); } // ensure sender has enough balance to execute transaction @@ -656,7 +657,14 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi } } - function _adjustBuffer(ISuperfluidToken token, address pool, address from, bytes32 flowHash, FlowRate newFlowRate) + function _adjustBuffer( + ISuperfluidToken token, + address pool, + address from, + bytes32 flowHash, + FlowRate oldFlowRate, + FlowRate newFlowRate + ) internal { // not using oldFlowRate in this model @@ -670,11 +678,19 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi (, FlowDistributionData memory flowDistributionData) = _getFlowDistributionData(ISuperfluidToken(token), flowHash); + // preliminary value for new buffer amount, without minimum deposit applied // @note downcasting from uint256 -> uint32 for liquidation period Value newBufferAmount = newFlowRate.mul(Time.wrap(uint32(liquidationPeriod))); + // application of minimum deposit if (Value.unwrap(newBufferAmount).toUint256() < minimumDeposit && FlowRate.unwrap(newFlowRate) > 0) { - newBufferAmount = Value.wrap(minimumDeposit.toInt256()); + if (FlowRate.unwrap(newFlowRate) > FlowRate.unwrap(oldFlowRate)) { + // only apply if the flowrate increases + newBufferAmount = Value.wrap(minimumDeposit.toInt256()); + } else { + // otherwise keep the old buffer amount + newBufferAmount = Value.wrap(flowDistributionData.buffer.toInt256()); + } } Value bufferDelta = newBufferAmount - Value.wrap(uint256(flowDistributionData.buffer).toInt256());