Function: settleIncomingOrder(SettleParams params)
This function allows a trusted market contract created by the owner of the contract using the createMarket function to perform account settlement.
Inputs
paramsControl: Full control.
Constraints: N/A.
Impact: Contains the
takeraddress,quoteTokenandbaseToken, the sideBUYorSELL,settlementtype,takerQuoteAmountandtakerBaseAmount, and alsomakerCreditsinfo.
Branches and code coverage
Intended branches
the
sideisSide.BUY, thetakerFeeis equal to the expected fee.the
sideisSide.SELL, thetakerFeeis equal to the expected fee.the
settlementisINSTANTandSide.sideisBUY, the expected amount of thequoteTokenhas been transferred to the contract from thetaker.the
settlementisINSTANTandSide.sideisBUY, the expected amount of thebaseTokenhas been transferred to thetaker.the
settlementisINSTANTandSide.sideisSELL, the expected amount of thebaseTokenhas been transferred to the contract from thetaker.the
settlementisINSTANTandSide.sideisSELL, the expected amount of thequoteTokenhas been transferred to thetaker.the
settlementisACCOUNTandSide.sideisBUY, the expected amount of thequoteTokenhas been debited from thetakerbalance.the
settlementisACCOUNTandSide.sideisBUY, the expected amount of thebaseTokenhas been credited to thetakerbalance.the
settlementisACCOUNTandSide.sideisSELL, the expected amount of thebaseTokenhas been debited from thetakerbalance.the
settlementisACCOUNTandSide.sideisSELL, the expected amount of thequoteTokenhas been credited to thetakerbalance.
Negative behavior
The caller is not a trusted market.
Function call analysis
FeeDataLib.getTakerFee(ds.feeData, this.takerFees, params.taker, params.takerBaseAmount)What is controllable?
params.takerandparams.takerBaseAmount.If the return value is controllable, how is it used and how can it go wrong? Returns the fee amount charged from the taker based on the
takerBaseAmount. The fee for the account depends on theFeeTiersindex, which is set up by the owner. By default, this is equal toZEROindex.What happens if it reverts, reenters or does other unusual control flow? There are no problems here.
FeeDataLib.accrueFee(ds.feeData, params.baseToken, takerFee)What is controllable?
params.baseToken.If the return value is controllable, how is it used and how can it go wrong? This function does not return a value.
What happens if it reverts, reenters or does other unusual control flow? There are no problems here.
FeeDataLib.getTakerFee(ds.feeData, this.takerFees, params.taker, params.takerQuoteAmount)What is controllable?
params.takerandparams.takerQuoteAmount.If the return value is controllable, how is it used and how can it go wrong? Returns the fee amount charged from the taker based on the
takerQuoteAmount. The fee for the account depends on theFeeTiersindex, which is set up by the owner. By default, this is equal toZEROindex.What happens if it reverts, reenters or does other unusual control flow? There are no problems here.
FeeDataLib.accrueFee(ds.feeData, params.quoteToken, takerFee)What is controllable?
params.baseToken.If the return value is controllable, how is it used and how can it go wrong? This function does not return a value.
What happens if it reverts, reenters or does other unusual control flow? There are no problems here.
SafeTransferLib.safeTransferFrom(params.quoteToken, params.taker, address(this), params.takerQuoteAmount)What is controllable?
params.quoteToken,params.taker, andparams.takerQuoteAmount.If the return value is controllable, how is it used and how can it go wrong? This function does not return a value.
What happens if it reverts, reenters or does other unusual control flow? Transfers
takerQuoteAmountfrom the taker account if the side isBUY, representing the payment for filling the order.
SafeTransferLib.safeTransfer(params.baseToken, params.taker, params.takerBaseAmount)What is controllable?
params.baseToken,params.taker, andparams.takerBaseAmount.If the return value is controllable, how is it used and how can it go wrong? This function does not return a value.
What happens if it reverts, reenters or does other unusual control flow? Transfers
takerBaseAmountto the taker account if the side isBUY, representing the proceeds from filling the order.
SafeTransferLib.safeTransferFrom(params.baseToken, params.taker, address(this), params.takerBaseAmount)What is controllable?
params.baseToken,params.taker, andparams.takerBaseAmount.If the return value is controllable, how is it used and how can it go wrong? This function does not return a value.
What happens if it reverts, reenters or does other unusual control flow? Transfers
takerBaseAmountfrom the taker account if the side isSELL, representing the payment for filling the order.
SafeTransferLib.safeTransfer(params.quoteToken, params.taker, params.takerQuoteAmount)What is controllable?
params.quoteToken,params.taker, andparams.takerQuoteAmount.If the return value is controllable, how is it used and how can it go wrong? This function does not return a value.
What happens if it reverts, reenters or does other unusual control flow? Transfers
takerQuoteAmountto the taker account if the side isSELL, representing the proceeds from filling the order.
CLOBManagerStorageLib.debitAccount(ds, params.taker, params.quoteToken, params.takerQuoteAmount)What is controllable?
params.taker,params.quoteToken, andparams.takerQuoteAmount.If the return value is controllable, how is it used and how can it go wrong? This function does not return a value.
What happens if it reverts, reenters or does other unusual control flow? Decreases the internal account balance using the specified
takerQuoteAmountamount and reverts if the balance is insufficient.
CLOBManagerStorageLib.creditAccount(ds, params.taker, params.baseToken, params.takerBaseAmount)What is controllable?
params.taker,params.baseToken, andparams.takerBaseAmount.If the return value is controllable, how is it used and how can it go wrong? This function does not return a value.
What happens if it reverts, reenters or does other unusual control flow? Increases the internal account balance using the specified
takerBaseAmountamount.
CLOBManagerStorageLib.debitAccount(ds, params.taker, params.baseToken, params.takerBaseAmount)What is controllable?
params.taker,params.baseToken, andparams.takerBaseAmount.If the return value is controllable, how is it used and how can it go wrong? This function does not return a value.
What happens if it reverts, reenters or does other unusual control flow? Decreases the internal account balance using the specified
takerBaseAmountamount and reverts if the balance is insufficient.
CLOBManagerStorageLib.creditAccount(ds, params.taker, params.quoteToken, params.takerQuoteAmount)What is controllable?
params.taker,params.quoteToken, andparams.takerQuoteAmount.If the return value is controllable, how is it used and how can it go wrong? This function does not return a value.
What happens if it reverts, reenters or does other unusual control flow? Increases the internal account balance using the specified
takerQuoteAmountamount.
this._settleMakerFill(params.quoteToken, params.baseToken, params.makerCredits, params.side) -> FeeDataLib.getMakerFee(ds.feeData, this.makerFees, credit.maker, credit.quoteAmount)What is controllable?
credit.makerandcredit.quoteAmount.If the return value is controllable, how is it used and how can it go wrong? Returns the fee amount charged from the maker based on the
quoteAmount. The fee for the account depends on theFeeTiersindex, which is set up by the owner. By default, this is equal toZEROindex.What happens if it reverts, reenters or does other unusual control flow? There are no problems here.
this._settleMakerFill(params.quoteToken, params.baseToken, params.makerCredits, params.side) -> FeeDataLib.accrueFee(ds.feeData, quoteToken, makerFee)What is controllable?
quoteToken.If the return value is controllable, how is it used and how can it go wrong? This function does not return a value.
What happens if it reverts, reenters or does other unusual control flow? There are no problems here. But the fee will be charged only in the case when the
clobSideisBUY, and accordingly themakerside isSELLandcredit.quoteAmountis more than zero. Ifcredit.baseAmountis more than zero, in this case, it means than the maker order has been expired, the fee should not be charged, and the maker will get the full refund.
this._settleMakerFill(params.quoteToken, params.baseToken, params.makerCredits, params.side) -> FeeDataLib.getMakerFee(ds.feeData, this.makerFees, credit.maker, credit.baseAmount)What is controllable?
credit.makerandcredit.quoteAmount.If the return value is controllable, how is it used and how can it go wrong? Returns the fee amount charged from the maker based on the
baseAmount. The fee for the account depends on theFeeTiersindex, which is set up by the owner. By default, this is equal toZEROindex.What happens if it reverts, reenters or does other unusual control flow? There are no problems here.
this._settleMakerFill(params.quoteToken, params.baseToken, params.makerCredits, params.side) -> FeeDataLib.accrueFee(ds.feeData, baseToken, makerFee)What is controllable?
baseToken.If the return value is controllable, how is it used and how can it go wrong? This function does not return a value.
What happens if it reverts, reenters or does other unusual control flow? There are no problems here. But the fee will be charged only in the case when the
clobSideisSELL, and accordingly themakerside isBUYandcredit.baseAmountis more than zero. Ifcredit.quoteAmountis more than zero, in this case, it means than the maker order has been expired, the fee should not be charged, and the maker will get the full refund.
this._settleMakerFill(params.quoteToken, params.baseToken, params.makerCredits, params.side) -> CLOBManagerStorageLib.creditAccount(ds, credit.maker, quoteToken, credit.quoteAmount)What is controllable?
credit.makerandcredit.quoteAmount.If the return value is controllable, how is it used and how can it go wrong? This function does not return a value.
What happens if it reverts, reenters or does other unusual control flow? Increases the internal account balance using the specified
quoteAmountamount.
this._settleMakerFill(params.quoteToken, params.baseToken, params.makerCredits, params.side) -> CLOBManagerStorageLib.creditAccount(ds, credit.maker, baseToken, credit.baseAmount)What is controllable?
credit.makerandcredit.baseAmount.If the return value is controllable, how is it used and how can it go wrong? This function does not return a value.
What happens if it reverts, reenters or does other unusual control flow? Increases the internal account balance using the specified
baseAmountamount.