Deposits

contract Deposits is MainStorage, LibConstants, IVerifierActions, MFreezable, MOperator, MUsers, MTokens

For a user to perform a deposit to the contract two calls need to take place:

  1. A call to an ERC20 contract, authorizing this contract to trasnfer funds on behalf of the user.

  2. A call to deposit indicating the amount, token ID and target vault ID to which to send the deposit.

The amount should be quantized, according to the specific quantization defined for the token ID.

The result of the operation, assuming all requirements are met, is that an amount of ERC20 tokens equaling the amount specified in the deposit call times the quantization factor is transferred on behalf of the user to the contract. In addition, the contract adds the funds to an accumulator of pending deposits for the provided user, token ID and vault ID.

Once a deposit is made, the exchange may include it in a proof which will result in addition of the amount(s) deposited to the off-chain vault with the specified ID. When the contract receives such valid proof, it deducts the transfered funds from the pending deposits for the specified user, token ID and vault ID.

The exchange will not be able to move the deposited funds to the off-chain vault if the vault does not belong to the StarkKey associated with the user EthKey. However, this is not enforced by the contract but by the inability to create a valid STARK proof for such transfer.

Until that point, the user may cancel the deposit by performing a time-locked cancel-deposit operation consisting of two calls:

  1. A call to depositCancel, setting a timer to enable reclaiming the deposit. Until this timer expires the user cannot reclaim funds as the exchange may still be processing the deposit for inclusion in the off chain vault.

  2. A call to depositReclaim, to perform the actual transfer of funds from the contract back to the ERC20 contract. This will only succeed if the timer set in the previous call has expired. The result should be the transfer of all funds not accounted for in proofs for off-chain inclusion, back to the user account on the ERC20 contract.

Implements IVerifierActions.acceptDeposit. Uses MFreezable, MVerifiers, MUsers and MTokens.

event LogDeposit(uint256 starkKey, uint256 vaultId, uint256 tokenId, uint256 nonQuantizedAmount, uint256 quantizedAmount)
event LogDepositCancel(uint256 starkKey, uint256 vaultId, uint256 tokenId)
event LogDepositCancelReclaimed(uint256 starkKey, uint256 vaultId, uint256 tokenId, uint256 nonQuantizedAmount, uint256 quantizedAmount)
function getDepositBalance(uint256 starkKey, uint256 tokenId, uint256 vaultId)
external
view
returns (uint256 balance)
function getQuantizedDepositBalance(uint256 starkKey, uint256 tokenId, uint256 vaultId)
external
view
returns (uint256 balance)
function getCancellationRequest(uint256 starkKey, uint256 tokenId, uint256 vaultId)
external
view
returns (uint256 request)
function deposit(uint256 tokenId, uint256 vaultId, uint256 quantizedAmount)
public
 notFrozen()
function deposit(uint256 tokenId, uint256 vaultId)
external
payable
function depositCancel(uint256 tokenId, uint256 vaultId)
external
function depositReclaim(uint256 tokenId, uint256 vaultId)
external