FundLockTrade
Elektro triggered functionality of the FundLock.
View Source: contracts/fund-lock/FundLockTrade.sol
↗ Extends: FundLockBase, IFundLockTrade
FundLockTrade
Elektro trading related contract of FundLock group. Updates {balanceSheetS} and {fundsToWithdrawS} upon trade settlement, to finalize and manage client funds. Last stop for any trade settlement transaction.All functions besides balance getter can only be called by a registered Elektro contract.
Modifiers
isValidContract
isValidContract
Uses isValidContractOrUtility
function of RegistryBase
contract to verify that a caller of the function using this modifier is a valid Elektro contract.
Arguments
Functions
updateBalances(address[] traders, int256[] amounts, address[] tokens, uint64 backendId)
fundFromWithdrawn(address beneficiary, address token, uint256 toFundAmt)
_updateBalance(address trader, address assetAddress, int256 amount)
updateBalances
Public function used by Elektro to update balanceSheetS
for all types of accounts. Used by LedgerUpdate flows. Updates trader balances by calling single update function {_updateBalance}, emits event.
Arguments
traders
address[]
- array of all clients accounts of the settlement batch
amounts
int256[]
- array of amounts of funds to update client balances with
tokens
address[]
- array of token addresses for each update row
backendId
uint64
- identificator created by Java Backend to track settlement progress
fundFromWithdrawn
Private function that is a part of {_updateBalance}. This function is only called when user's funds in {balanceSheets} are not enough and his {fundsToWithdrawS} can be used.Checks every struct bound to user and a particular token for trade availability (if {tradeLock} interval hasn't yet passed). Changes values of all necessary structs according to funding amount. Zeros out {balanceSheetS} if all structs have been changed and all funds are used.
Returns
funded - a boolean representing if there were enough funds to fully pay for what's needed, if it's false, the transaction using this flow will fail because this call is usually wrapped in a require()
Arguments
beneficiary
address
- address of a client whose funds we're using.
token
address
- address of a token to use.
toFundAmt
uint256
- total amount to fund from all {fundsToWithdrawS}.
_updateBalance
Internal low level function to update a single entry in the {balanceSheetS} for a client. Checks if a client has enough funds in his {balanceSheetS} for a particular token, if so - that balance is used to cover his trade, if not - call to {fundFromWithdrawS} to check and use his funds marked for withdrawal that are still viable for usage ({tradeLock} is on). If those funds are not enough as well - revert, otherwise, his {fundFromWithdrawS} becomes smaller.
Arguments
trader
address
- client's address to update balance for
assetAddress
address
- address of the token used
amount
int256
- signed int which is used to update balance
Last updated
Was this helpful?