withdraw - atticplaygroup/prex GitHub Wiki
Following successful sales on Prex, sellers have the option to withdraw their earnings as Sui tokens, with potential support for additional currencies in the future. The design aims to prevent insolvency by ensuring sufficient funds are always available for withdrawals. This requires implementing atomic transactions and collecting fees to cover gas costs and any external charges.
Withdrawals are processed using collected priority fees. A withdrawal transaction is initiated only when the total priority fees collected surpass the gas costs involved. In practice, Prex operators may enforce a minimum priority fee requirement for withdrawals.
The withdrawal process takes advantage of the fact that Sui transactions are idempotent. Transactions will be sent repeatedly until it successfully gets finalized.
Caution
Gas budget of a dispatched transaction never changes.
A transaction may get refused for a long time when the gas price raises, preventing transaction being included. In this case Prex will still repeat the same transaction until the gas price drops below the original level.
Upon a user's withdrawal request, the corresponding funds are locked. During this phase, the user retains the option to cancel the withdrawal.
A scheduled task regularly examines the list of withdrawals in this waiting state, gathering priority fees from the highest to the lowest. If the total priority fees collected exceed the estimated gas cost, the task will process the withdrawals by constructing a Sui transaction and dispatching the funds to the designated addresses. The withdrawal addresses are allowed to differ from the deposit addresses. When being processed, the status is set to processing
and funds inside Prex for this transaction are burned.
If a check of the blocks before the expiration epoch confirms the transaction's success, the withdrawal status will be updated to succeeded
.
To prevent unbounded database growth, transactions with success
status will be purged after a certain period of time has elapsed.