MultiAccount (0.8.4)
MultiAccount (0.8.4)
The MultiAccount module enables users to create sub‑accounts that are whitelisted to interact with hedgers. These sub‑accounts allow positions to be either in cross (all positions sharing collateral) or isolated (separate sub‑accounts). In addition to standard account creation and fund management, MultiAccount introduces robust access delegation features. In version 0.8.4, a key update is the two‑step revocation process for delegated access.
New Revocation Process: In earlier versions, users could revoke delegated access instantly. However, this sometimes led hedgers to execute actions (like sending quotes on behalf of users) only to have their access revoked unexpectedly. Now, users must first propose revocation using the
proposeToRevokeAccesses
method. After a configured cooldown period elapses, they can then revoke the access with therevokeAccesses
method. This ensures that hedgers have advanced notice before their access is removed.
Initialization and Setup
initialize()
Initializes the MultiAccount contract with the necessary roles and addresses. It sets the administrator, the address of the Symmio platform, and the bytecode for the account implementation.
Function Signature:
Parameters:
admin
: The administrator’s address (granted default admin, pauser, unpauser, and setter roles).symmioAddress_
: The address of the Symmio platform.accountImplementation_
: The bytecode for the account implementation to be used for deploying sub‑accounts.
Example Usage:
Account Management
addAccount()
Creates a new sub‑account for the caller with a specified name. Each new account is deployed using the current account implementation and is mapped to the owner’s address.
Function Signature:
Parameters:
name: The name of the new sub‑account.
Example Usage:
Events Emitted:
AddAccount(address owner, address account, string name)
editAccountName()
Allows the owner to change the name of an existing sub‑account.
Function Signature:
Parameters:
accountAddress: The address of the sub‑account to rename.
name: The new name for the account.
Example Usage:
Events Emitted:
EditAccountName(address owner, address account, string newName)
depositForAccount()
Deposits funds into a sub‑account from the owner’s balance. It calls the Symmio platform’s deposit function on behalf of the account.
Function Signature:
Parameters:
account: The address of the sub‑account.
amount: The amount to deposit.
Example Usage:
Events Emitted:
DepositForAccount(address owner, address account, uint256 amount)
depositAndAllocateForAccount()
Deposits funds into a sub‑account and immediately allocates them for trading. The deposited amount is converted to 18 decimals before being allocated.
Function Signature:
Parameters:
account: The address of the sub‑account.
amount: The amount to deposit and allocate.
Example Usage:
Events Emitted:
DepositForAccount(address owner, address account, uint256 amount)
AllocateForAccount(address owner, address account, uint256 amountWith18Decimals)
withdrawFromAccount()
Withdraws funds from a sub‑account back to the owner’s address. It calls the Symmio platform’s withdrawal function.
Function Signature:
Parameters:
account: The address of the sub‑account.
amount: The amount to withdraw.
Example Usage:
Events Emitted:
WithdrawFromAccount(address owner, address account, uint256 amount)
Access Delegation and Revocation
delegateAccess()
Description: Allows the owner of a sub‑account to delegate access to a target address for a specific function. This enables external addresses (such as hedgers) to perform actions on behalf of the sub‑account.
Function Signature:
Parameters:
account: The address of the sub‑account.
target: The target contract address for which access is delegated.
selector: The function selector (first 4 bytes of the function signature) for which access is granted.
Example Usage:
Events Emitted:
DelegateAccess(address account, address target, bytes4 selector, bool state)
(state will betrue
)
delegateAccesses()
Batch version of delegateAccess
. Delegates access for multiple function selectors at once.
Function Signature:
Parameters:
account: The sub‑account address.
target: The target contract address.
selector: An array of function selectors to delegate access for.
Example Usage:
Events Emitted:
DelegateAccesses(address account, address target, bytes4[] selectors, bool state)
(state will betrue
)
proposeToRevokeAccesses()
Proposes revoking delegated access from a target address for one or more function selectors. The proposal timestamp is recorded. Revocation does not take effect immediately; it only becomes actionable after the cooldown period.
Function Signature:
Parameters:
account: The sub‑account address.
target: The target contract address from which access is to be revoked.
selector: An array of function selectors for which revocation is proposed.
Example Usage:
Events Emitted:
ProposeToRevokeAccesses(address account, address target, bytes4[] selectors)
revokeAccesses()
After the revoke cooldown period has elapsed, this function allows the owner to revoke delegated access for the specified function selectors from a target address.
Function Signature:
Parameters:
account: The sub‑account address.
target: The target contract address from which access will be revoked.
selector: An array of function selectors to revoke.
Example Usage:
Events Emitted:
DelegateAccesses(address account, address target, bytes4[] selectors, bool state)
(state will befalse
)
setRevokeCooldown()
Sets the cooldown period for the revocation process. This determines how long after proposing revocation the owner must wait before actually revoking access.
Function Signature:
Parameters:
cooldown: The new cooldown period in seconds.
Example Usage:
Events Emitted:
SetRevokeCooldown(uint256 oldCooldown, uint256 newCooldown)
Configuration and Address Management
setAccountImplementation()
Updates the bytecode for the account implementation used to deploy new sub‑accounts.
Function Signature:
Parameters:
accountImplementation_: The new account implementation bytecode.
Example Usage:
Events Emitted:
SetAccountImplementation(bytes oldImplementation, bytes newImplementation)
setSymmioAddress()
Updates the address of the Symmio platform with which the MultiAccount contract interacts.
Function Signature:
Parameters:
addr: The new Symmio platform address.
Example Usage:
Events Emitted:
SetSymmioAddress(address oldAddress, address newAddress)
Internal Functions
_deployPartyA()
Deploys a new Party A sub‑account using the current account implementation and a unique salt (via create2).
Function Signature:
Example:
This function is called internally by addAccount
.
_deployContract()
Deploys a contract using the create2 opcode with the specified bytecode and salt.
Function Signature:
Example:
Called by _deployPartyA
to deploy a new sub‑account.
Pausable Functionality
pause() / unpause()
Allows authorized users (with PAUSER_ROLE/UNPAUSER_ROLE) to pause or unpause the MultiAccount contract, halting or resuming all operations.
Function Signatures:
Example Usage:
View Functions
getAccountsLength()
Description: Returns the number of sub‑accounts owned by a specific user.
Function Signature:
Example Usage:
getAccounts()
Retrieves an array of sub‑accounts owned by a user, with pagination parameters.
Function Signature:
Parameters:
user: The owner’s address.
start: The starting index.
size: The number of accounts to return.
Example Usage:
Last updated