# Closing of deposits

Deposit can be closed by the player and by you upon different conditions (see Closing of deposit and withdrawal in the user documentation). When a deposit gets closed the Smart Contract determines if the player has won or lost funds with respect to the amount initially deposited. From now on we will use winning deposit to refer to deposits that are closed with a balance higher than the amount deposited and losing deposit to refer to deposits that are closed with a balance below the amount deposited.

We assume that you have read the user documentation and you have an understanding of the deposit closing mechanism.
Here we recap the rules and conditions that the Smart Contract uses to regulate the closing of deposits:

  • both parties (player and you) can close the deposit upon different conditions
  • being the owner of the deposit the player can request the Smart Contract to close it at anytime
  • you, as the other party, can only request the Smart Contract to close a deposit while it is losing (meaning that the current balance is below the amount initially deposited) and one of the following conditions is met:
    • the balance is below the minimum-balance
    • the time elapsed since the creation of the deposit exceeds the minimum-deposit-duration
  • when one of the two parties has requested the Smart Contract to close a deposit the other party has a time equal to counter-close-timeout to counter close the deposit by submitting its know state for it (the state represents the final balance and its signatures made by both parties)
  • in order to request the Smart Contract to close a deposit (or to counter close a deposit that was requested to be closed by the other party) each party must submit to the Smart Contract its known state for that deposit, together with the signature of that state made by both parties. This guarantees that nobody can request to close a deposit with a state that has not been approved and signed by the other party
  • the Smart Contract only closes the deposit once it has received the closing request from both parties. When one party requests to close the deposit and the second party does not submit its counter close request in time then the Smart Contract allows the first party to close the deposit by submitting a new close request to finalize its closing.
  • When the Smart Contract has received and validated the closing requests made by both parties it will close the deposit with the balance that corresponds to the most recent state out of the two requests received. This is done by taking the state that corresponds to the highest Nonce
  • the player can request the Smart Contract to close a deposit submitting a state with a balance equal to the amount deposited and no signatures for it. This is the only case where the Smart Contract accepts a closing request that does not provide the signatures made by both parties. This excpetion is to allow the player to withdraw the funds that he has deposited when he hasn't played any game as in this case the two signatures are not available. It's important to underline that even in this case the Smart Contract still waits a time equal to counter-close-timeout for the other party to submit a counter close request with its known state.
  • the value of minimum-deposit-duration represents the initial duration of a deposit and prevents you from being able to request the closing of a losing deposit until this time has elapsed since the creation of the deposit. Players can extend the duration of a deposit by adding more funds to it. The deposit duration is extended by a time that correponds to the initial duration multiplied by the ratio between the funds that are being added and the initial amount deposited. When the amount of funds added is higher than what was deposited originally then the duration is only extended by a time equal to the initial duration.
    Example: when minimum-deposit-duration is set to one week, adding 100$ or adding 200$ to a 100$ deposit increases the deposit duration by one more week, while adding 50$ to a 100$ deposit increases the duration by half a week