ElektroLedgerUpdate.sol
View Source: contracts/elektro/ledger/ElektroLedgerUpdate.sol
↗ Extends: ElektroStorage, ElektroLedgerCommon, IElektroLedgerUpdate
ElektroLedgerUpdate
Main functionality of an Elektro market. Contract for settling trades based on the data passed from Java Backend Engine. Some data validation, calculations and calls to FundLock Module to make transfers and update token balances.
Functions
updatePositions(address[] positionClients, uint32[] positionContractIds, int64[] positionSizes, address[] fundMovementClients, int64[] underlyingAmounts, int64[] strikeAmounts, uint64 backendId)
validateAndCountAmounts(int64[] underlyingAmounts, int64[] strikeAmounts)
processPositionUpdates(address[] clientAddresses, uint32[] positionContractIds, int64[] positionSizes)
processFundMovement(address[] fundMovementClients, int64[] underlyingAmounts, int64[] strikeAmounts, uint64 backendId, uint256 transferCount)
initializeData(address[] fundMovementClients, int64[] underlyingAmounts, int64[] strikeAmounts, uint256 transferCount)
updatePositions
Entry point for all settlement logic and the function that Java Backend calls to trigger trade settlement. Checks arguments, updates position balances for a market in {ElektroStorage}, normalizes values to token denomination and calls FundLock to update token balances for each client. Arguments are broken down in two groups:
Postiion update in ElektroStorage,
Fund movements/client balances update in FundLockStorage.
Please note: Signs of the values for both of the below amount args are inverted, meaning that a negative amount would be added to an existing client balance, while a positive value is going to be subtracted! Negative means client receives tokens, positive means he pays tokens.
Arguments
Name | Type | Description |
---|---|---|
positionClients | address[] | - addresses of the traders for whom positions are being changed |
positionContractIds | uint32[] | - contractIds for each position (representation of a trade contract under which we are settling) |
positionSizes | int64[] | - difference number representing how a position is going to change Negative position is going to be subtracted from an existing one, while a positive is going to be added. |
fundMovementClients | address[] | - addresses of the client for which funds are going to be moved/updated |
underlyingAmounts | int64[] | - signed amounts of fund movements in underlying asset |
strikeAmounts | int64[] | - signed amounts of fund movements in strike/price asset |
backendId | uint64 | - identificator created by Java Backend to track settlement progress |
validateAndCountAmounts
Function that validates that there are no fully zero rows present and counts how many transfers will be needed when reaching FundLock, so we can create correct length transfer arrays for FundLock.
Returns
transferCount - the amount of non zero amounts that would make a valid transger in FundLock
Arguments
Name | Type | Description |
---|---|---|
underlyingAmounts | int64[] | - see {updatePositions()} |
strikeAmounts | int64[] | - see {updatePositions()} |
processPositionUpdates
Function for updating clientPositions
mapping in {ElektroStorage}
Arguments
Name | Type | Description |
---|---|---|
clientAddresses | address[] | - addresses of the traders for whom positions are being changed |
positionContractIds | uint32[] | - contractIds for each position (representation of a trade contract under which we are settling) |
positionSizes | int64[] | - difference number representing how a position is going to change |
processFundMovement
Preparation of the "fund movement" part of the data where we take initial arrays and convert them into arrays that FundLock can understand. Creating new arrays, inverting and normalizing values to token denomination for the upcoming transfers in FundLock + sending these arrays to FundLock for further settlement.
Arguments
Name | Type | Description |
---|---|---|
fundMovementClients | address[] | - addresses of the client for which funds are going to be moved/updated |
underlyingAmounts | int64[] | - signed amounts of fund movements in underlying asset |
strikeAmounts | int64[] | - signed amounts of fund movements in strike/price asset |
backendId | uint64 | - identificator created by Java Backend to track settlement progress |
transferCount | uint256 | - the amount of transfers between balances that will be performed by FundLock, needed to create non-dynamic memory arrays to fill with prepared data |
initializeData
The actual data preparation function in order to move settlement further to FundLock. Creates new arrays, gets {CurrencyPair} to further perform amounts conversion to token denomination and inverts signs for proper balance updates. Only non-negative values are used.
Returns
traders - array of clients/traders for whom FundLock balances will be updated
Arguments
Name | Type | Description |
---|---|---|
fundMovementClients | address[] | - addresses of the client for which funds are going to be moved/updated |
underlyingAmounts | int64[] | - signed amounts of fund movements in underlying asset |
strikeAmounts | int64[] | - signed amounts of fund movements in strike/price asset |
transferCount | uint256 | - the amount of transfers between balances that will be performed by FundLock, needed to create non-dynamic memory arrays to fill with prepared data |
Last updated