Skip to main content

Custody

What is Custody?#

In our project, we allow user to connect their Metamask wallet onto our platform, providing them a more secure environment for their assets. Users can then deposit funds onto the custody wallet. This deposit to the custody wallet will then open a state channel off-chain. By following nitro protocols on the state channel, we can then have instant finality to user balances after each transaction. This allows the user to have locked balances and make partial/full withdrawals from the custody wallet, back to the Metamask.

Smart Contracts

IVault#

IVault is the interface to implement custody

Contents#

Functions#

getLastId#

📋    Get last ledger id (deposits and withdrawals id).

Declaration#
  function getLastId(  ) external returns (uint256)
Returns:#
TypeDescription
uint256Ledger id.

Events#

Deposited#

📋    Deposited event

Params:#
ParamTypeIndexedDescription
iduint256Ledger id
accountaddressAccount address
assetaddressAsset address to deposit
amountuint256Quantity of assets to be deposited

Withdrawn#

📋    Withdrawn event

Params:#
ParamTypeIndexedDescription
iduint256Ledger id
accountaddressAccount address
assetaddressAsset address to deposit
amountuint256Quantity of assets to be deposited

SimpleVault#

Custody smart contracts aim to provide a secure trading environment by holding the assets on the erc20 chain so that the user and broker can freely trade off-chain.

Contents#

Globals#

VarTypeDescription
BROKER_ROLEbytes32Broker role identifier value
WITHDRAW_TYPEbytes32Withdrawal type identifier value

Modifiers#

onlyValidMovingFundParams#

📋    Modifier to check information required for deposits and withdrawals.

Declaration#
  modifier onlyValidMovingFundParams(    address account  )
Args:#
ArgTypeDescription
accountaddressAccount address to check

Functions#

initialize#

📋    The constructor function sets the contract name and broker's address.

Declaration#
  function initialize(    string name_,    address broker_  ) public initializer
Modifiers:#
Modifier
initializer
Args:#
ArgTypeDescription
name_stringContract name
broker_addressBroker name

name#

📋    Get contract name.

Declaration#
  function name(  ) public returns (string)
Returns:#
TypeDescription
stringContract name

changeBroker#

📋    Change broker address who signed the withdrawal signature.

Declaration#
  function changeBroker(    address newBroker  ) external onlyRole
Modifiers:#
Modifier
onlyRole
Args:#
ArgTypeDescription
newBrokeraddressBroker address

getLastId#

📋    Get last ledger id (deposits and withdrawals id).

Declaration#
  function getLastId(  ) external returns (uint256)
Returns:#
TypeDescription
uint256Ledger id.

deposit#

📋    Deposit the asset with given amount into custody

Declaration#
  function deposit(    address asset,    uint256 amount  ) public returns (bool)
Args:#
ArgTypeDescription
assetaddressAsset address to deposit
amountuint256Quantity of assets to be deposited
Returns:#
TypeDescription
boolReturn 'true' when deposited

_deposit#

📋    Internal deposit process and increment ledger id

Declaration#
  function _deposit(    address account,    address asset,    uint256 amount  ) internal onlyValidMovingFundParams returns (bool)
Modifiers:#
Modifier
onlyValidMovingFundParams
Args:#
ArgTypeDescription
accountaddressAccount address
assetaddressAsset address to deposit
amountuint256Quantity of assets to be deposited
Returns:#
TypeDescription
boolReturn 'true' when deposited

withdraw#

📋    Withdraw the asset with given payload to the caller

Declaration#
  function withdraw(    bytes payload,    bytes signature  ) public returns (bool)
Args:#
ArgTypeDescription
payloadbytesWithdrawal payload consists of rid (unique identifier id), deadline, destination, and the list of withdrawal asset and amount
signaturebytesBroker signature
Returns:#
TypeDescription
boolReturn 'true' when withdrawn

_withdraw#

📋    Internal withdraw process and increment ledger id

Declaration#
  function _withdraw(    address account,    bytes payload,    bytes signature  ) internal onlyValidMovingFundParams returns (bool)
Modifiers:#
Modifier
onlyValidMovingFundParams
Args:#
ArgTypeDescription
accountaddressAccount address
payloadbytesWithdrawal payload consists of rid (unique identifier id), deadline, destination, and the list of withdrawal asset and amount
signaturebytesBroker signature
Returns:#
TypeDescription
boolReturn 'true' when withdrawn

_transferAssetFrom#

📋    Transfers the given amount of this AssetHolders's asset type from a supplied ethereum address.

Declaration#
  function _transferAssetFrom(    address asset,    address from,    uint256 amount  ) internal
Args:#
ArgTypeDescription
assetaddressAsset address to transfer
fromaddressEthereum address to be credited
amountuint256Quantity of assets to be transferred

_transferAssetTo#

📋    Transfers the given amount of this AssetHolders's asset type to a supplied ethereum address.

Declaration#
  function _transferAssetTo(    address asset,    address destination,    uint256 amount  ) internal
Args:#
ArgTypeDescription
assetaddressAsset address to transfer
destinationaddressEthereum address to be credited
amountuint256Quantity of assets to be transferred