-
Notifications
You must be signed in to change notification settings - Fork 24
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
Add shortcut to operator for disburse and cancel pending order #534
Comments
nice idea. |
I just looked at I reviewed the tranche code and it seems like one could have both a supply order & redeem order active at the same time. Is this correct? If not, the code would get slightly more complicated. The below method would mean that no matter what action you wanted to do, you could always do it in one transaction. As they are written now, they only use existing public methods and should not pose any additional security risk and need in-depth testing. I posted both variations: function order(uint supplyAmount, uint redeemAmount) public note {
require(supplyAmount == 0 || redeemAmount == 0, "tinlake/operator-invalid-args"
payoutCurrencyAmount, payoutTokenAmount, remainingSupplyCurrency, remainingRedeemToken = tranche.calcDisburse()
if (payoutCurrencyAmount > 0 || payoutTokenAmount > 0) {
disburse()
}
if (remainingRedeemToken > 0 || redeemAmount> 0) {
redeemOrder(redeemAmount);
}
if (remainingSupplyCurrency > 0 || supplyAmount > 0) {
supplyOrder(supplyAmount);
}
} function order(uint supplyAmount, uint redeemAmount) public note {
require(supplyAmount == 0 || redeemAmount == 0, "tinlake/operator-invalid-args"
payoutCurrencyAmount, payoutTokenAmount, remainingSupplyCurrency, remainingRedeemToken = tranche.calcDisburse()
if (payoutCurrencyAmount > 0 || payoutTokenAmount > 0) {
tranche.disburse(msg.sender)
}
bool triggered;
if (remainingRedeemToken > 0) {
triggered = true;
redeemOrder(redeemAmount);
}
if (remainingSupplyCurrency > 0) {
triggered = true;
supplyOrder(supplyAmount);
}
if (triggered) return;
if (redeemAmount > 0) redeemOrder(redeemAmount);
if (supplyAmount > 0) supplyOrder(supplyOrder);
} |
We could use option A. It is possible to make an redeem and a supply order at the same time even if it makes logical no sense but otherwise we would have additional code to prevent it. I think you can also do it like that to make it more gas efficient. The function order(uint supplyAmount, uint redeemAmount) public note {
require(supplyAmount == 0 || redeemAmount == 0, "tinlake/operator-invalid-args");
uint remainingSupplyCurrency = 0;
uint remainingRedeemToken = 0;
if (tranche.users(msg.sender).orderedInEpoch() <= epochTicker.lastEpochExecuted()) {
( , , remainingSupplyCurrency, remainingRedeemToken = tranche.disburse();
}
if (remainingRedeemToken > 0 || redeemAmount > 0) {
redeemOrder(redeemAmount);
}
if (remainingSupplyCurrency > 0 || supplyAmount > 0) {
supplyOrder(supplyAmount);
}
}
|
We should add an extra method to the operator contract that will disburse and cancel any pending order in one transaction. It can be done as follows:
The text was updated successfully, but these errors were encountered: