Account Facet
Functions related to Account Management
The AccountFacetImpl.sol
library manages account-related operations within the SYMM contracts, focusing on deposits, withdrawals, and allocation of funds. It interacts with several storage structures to manage account balances, ensure compliance with cooldown periods, and handle liquidation statuses.
The AccountFacet.sol
handles the emitting of events related to the implementation's functions.
How allocation works in our system
After depositing collateral to the SYMM Diamond, the user cannot trade with it yet. It is required to allocate that money to a subaccount, then the user can start trading. Sub-accounts are isolated instances, as SYMMIO is 100% economically sound, all PartyA
<> PartyB
instances are isolated in subaccounts. Collateral deposited into a subaccount is in cross with all positions opened using that subaccount. To have an isolated position, a seperate subaccount should be created. Subaccounts also enable further customization down the road, where collateral could be allocated to a specific contract instance, with customized code written by PartyA
or PartyB
.
When a user allocates, they specify a fraction of, or the entire deposited amount to engage in trading. This specification is factored in when assessing the user's liquidity status, regardless of the total amount the user has deposited. When a user deallocates, they return a portion, or even the entirety, of their allocation back into their deposits. A withdrawal cooldown is applied to deallocated funds.
PartyA Function Overview
deposit()
Description: This function allows users to deposit tokens into the SYMM Diamond, to be allocated to sub-accounts for trading.
The designated token to serve as collateral is predetermined following the deployment of the contract, in current SYMMIO version each contract has a unique collateral type, for multi collateral support multiple base contracts can be deployed. It is important to note that whatever design decision gets taken in later versions, it is critical to hard require both Parties to use the same collateral when entering into a trade, in this SYMMIO version that hard requirement is enforced by having a single collateral class per contract. (see the ControlFacet.setCollateral
function).
There's also the functionality for a user to deposit funds on behalf of another user utilizing the depositFor
method.
Implementation:
Input Parameters:
user
: the address of the user.amount
: the amount of tokens to deposit to the user.
Storage Interactions: Updates the user's balance in AccountStorage
.
Event Structure:
withdraw()
Description: Enables users to withdraw tokens from their account after a cooldown period. This collateral must first be de-allocated before it can be withdrawn.
Funds that have been deposited but not yet allocated can be returned to the user's wallet. Additionally, there's a required waiting period between the deallocation and withdrawal processes. The waiting period can and will be used for independent watch dogs and security researcher to detect potential malicious behaviour between PartyA and PartyBs and can therefore be used to suspend those malicious parties, suspended Parties are not able to withdraw their de-allocated funds after the withdrawal period. It's a typical Fraud Proof window also used in optimistic rollups, one could therefore describe SYMMIO as something vaguely similiar to an L3.
Implementation:
Input Parameters:
user
: the address of the user.deposiamount
: the amount of tokens to deposit to the user.
Key Validations: Ensures the cooldown period is respected using MAStorage
.
Storage Interactions: Decreases the user's balance via accountLayout.balances
in AccountStorage
.
Event Structure:
allocate()
Description: Allocates a specified amount of funds to an account.
A user can specify a fraction of, or the entire deposited amount to engage in trading. This specification is factored in when assessing the user's liquidity status, regardless of the total amount the user has deposited.
Implementation:
Input Parameters:
amount
: the amount of tokens to deposit to the user.
Storage Interactions: Modifies the allocatedBalances
mapping in AccountStorage
.
Event Structure:
depositAndAllocate()
Description: Combines the deposit()
and allocate()
functions into one function for user convenience.
Event Structure:
deallocate()
Description: Deallocates funds previously allocated to a user account.
If not utilized elsewhere, users have the option to return a portion, or even the entirety, of their allocation back into their deposits.
Implementation:
Input Parameters:
amount
: the amount of tokens to deposit to the user.upnlSig
: a cryptographic signature obtained from Muon to verify user upnl. This is a factor in determining whether the user has enough capital todeallocate()
without facing liquidation.
Verifications: Verifies the signature using LibMuon.verifyPartyAUpnl
, then assesses if the user's availableBalance
exceeds the amount they're requesting to deallocate.
Storage Interactions: Adjusts allocated and free balances, updates nonces and sets the cooldown start time in AccountStorage
.
Event Structure:
PartyB Function Overview
transferAllocation()
Description: Transfers allocated funds from one partyB
to another, ensuring both parties meet solvency requirements.
Implementation:
Input Parameters:
amount
: the amount of tokens to deposit to the user.origin
: the address of the user transferring collateral.recipient
: the address of the recipient of the collateral.upnlSig
: a cryptographic signature obtained from Muon to verify upnl.
Verifications:
Requires that the partyB is not marked as liquidated in regards to the origin address.
Requires that partyB is not marked as liquidated in regards to the recipient address.
Requires that both the origin and recipient are not marked as liquidated.
Requires that the partyB allocated balance for the origin address exceeds the amount to transfer.
Calls
LibMuon.verifyPartyBUpnl
to ensure that partyB will not be liquidated upon executing this function.
Storage Interactions: Adjusts allocated balances between users in AccountStorage
.
Events Emitted:
allocateForPartyB()
Description: Allocates funds to a partyB
, with respect to a partyA
.
Implementation:
Input Parameters:
amount
: the amount of tokens to deposit to the user.partyA
: the address of the partyA.
Verifications: Ensures Party B's is solvent to call this function.
Storage Interactions: Modifies balances in AccountStorage
to reflect allocation.
Events Emitted:
deallocateForPartyB()
Description: Reverses allocations made for partyB
with respect to a partyA
, ensuring funds are returned to the user's balance.
Implementation:
Input Parameters:
amount
: the amount of tokens to deposit to the user.partyA
: the address of the partyA.upnlSig
: a cryptographic signature obtained from Muon to verify account upnl.
Verifications: Verifies the signature using LibMuon.verifyPartyAUpnl
, then assesses if the user's availableBalance
exceeds the amount they're requesting to deallocate.
Storage Interactions: Adjusts allocated and free balances, updates nonces and sets the cooldown start time in AccountStorage
.\
Last updated