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

[ETHEREUM-CONTRACTS] never increase buffer when decreasing flowrate #1842

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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());
Expand Down
Loading