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
params
Control: Full control.
Constraints: N/A.
Impact: Contains the
taker
address,quoteToken
andbaseToken
, the sideBUY
orSELL
,settlement
type,takerQuoteAmount
andtakerBaseAmount
, and alsomakerCredits
info.
Branches and code coverage
Intended branches
the
side
isSide.BUY
, thetakerFee
is equal to the expected fee.the
side
isSide.SELL
, thetakerFee
is equal to the expected fee.the
settlement
isINSTANT
andSide.side
isBUY
, the expected amount of thequoteToken
has been transferred to the contract from thetaker
.the
settlement
isINSTANT
andSide.side
isBUY
, the expected amount of thebaseToken
has been transferred to thetaker
.the
settlement
isINSTANT
andSide.side
isSELL
, the expected amount of thebaseToken
has been transferred to the contract from thetaker
.the
settlement
isINSTANT
andSide.side
isSELL
, the expected amount of thequoteToken
has been transferred to thetaker
.the
settlement
isACCOUNT
andSide.side
isBUY
, the expected amount of thequoteToken
has been debited from thetaker
balance.the
settlement
isACCOUNT
andSide.side
isBUY
, the expected amount of thebaseToken
has been credited to thetaker
balance.the
settlement
isACCOUNT
andSide.side
isSELL
, the expected amount of thebaseToken
has been debited from thetaker
balance.the
settlement
isACCOUNT
andSide.side
isSELL
, the expected amount of thequoteToken
has been credited to thetaker
balance.
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.taker
andparams.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 theFeeTiers
index, which is set up by the owner. By default, this is equal toZERO
index.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.taker
andparams.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 theFeeTiers
index, which is set up by the owner. By default, this is equal toZERO
index.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
takerQuoteAmount
from 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
takerBaseAmount
to 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
takerBaseAmount
from 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
takerQuoteAmount
to 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
takerQuoteAmount
amount 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
takerBaseAmount
amount.
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
takerBaseAmount
amount 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
takerQuoteAmount
amount.
this._settleMakerFill(params.quoteToken, params.baseToken, params.makerCredits, params.side) -> FeeDataLib.getMakerFee(ds.feeData, this.makerFees, credit.maker, credit.quoteAmount)
What is controllable?
credit.maker
andcredit.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 theFeeTiers
index, which is set up by the owner. By default, this is equal toZERO
index.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
clobSide
isBUY
, and accordingly themaker
side isSELL
andcredit.quoteAmount
is more than zero. Ifcredit.baseAmount
is 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.maker
andcredit.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 theFeeTiers
index, which is set up by the owner. By default, this is equal toZERO
index.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
clobSide
isSELL
, and accordingly themaker
side isBUY
andcredit.baseAmount
is more than zero. Ifcredit.quoteAmount
is 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.maker
andcredit.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
quoteAmount
amount.
this._settleMakerFill(params.quoteToken, params.baseToken, params.makerCredits, params.side) -> CLOBManagerStorageLib.creditAccount(ds, credit.maker, baseToken, credit.baseAmount)
What is controllable?
credit.maker
andcredit.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
baseAmount
amount.