-
Notifications
You must be signed in to change notification settings - Fork 21
Manual Withdraws (Direct from V3 Smart Contract)
Manual withdraws should only be used as a last resort to retrieve funds directly from the smart contract in the event that the Switcheo Exchange API is FUBAR. It is not meant for everyday use, and is not for the faint hearted. Manual withdraws from the exchange smart contract requires understanding and some expertise on how to construct and broadcast a NEO transaction on the blockchain directly.
In NEO V3 contract the order books are managed in an off-chain service. This off-chain service helps us to verify that the transaction that are queued to be broadcasted can be broadcasted perfectly onto the blockchain at a future time.
To provide instantaneous transactions and prevent our off-chain service from having inaccurate contract balances, there is a buffer time (currently set to 7 days) before any actions can be fully executed.
This means users will need to wait for the delay to finish before manual withdraw can be completed. However, it does not mean that Switcheo Exchange has custody of user funds at any time.
- Announce a withdrawal by calling the smart contract operation:
announceWithdraw
- Operation: announceWithdraw
- Parameters:
- 0:
withdrawer
- Script hash of user's address - 1:
assetID
- Script hash of the asset ID to withdraw - 2:
amountToWithdraw
- Amount to withdraw (as an integer)
- 0:
- Wait for the buffer time
announceDelay
- Skip to step 5 if this is a NEP-5 withdrawal, if not proceed to step 4 to continue a system asset withdrawal
- Reserve UTXO for withdrawal by calling the smart contract operation:
withdraw
. The transaction is formed differently depending on whether the asset is NEO/GAS (System Asset) or a NEP-5 token. Note the difference in0xa2
vs0xa3
, as well as the value for0x20
, and witness scripts required.-
System Assets
- Operation:
withdraw
- Parameters: - None -
- Attributes:
-
0x20
:withdrawer
- Script hash of the user's address -
0xa1
:0x50
- Literal byte flag -
0xa3
:assetID
- Script hash of the asset ID to withdraw -
0xa4
:withdrawer
- Script hash of the user's address
-
- Witness
scripts
(signatures) required:- withdrawer
- Operation:
-
NEP-5 Tokens
- Operation:
withdraw
- Parameters: - None -
- Attributes:
-
0x20
:contractHash
- Script hash of the Switcheo Exchange smart contract -
0xa1
:0x50
- Literal byte flag -
0xa2
:assetID
- Script hash of the asset ID to withdraw -
0xa4
:withdrawer
- Script hash of the user's address
-
- Witness
scripts
(signatures) required:- withdrawer
- contract:
{ invocationScript: '0000', verificationScript: '' }
- Operation:
-
System Assets
- Complete withdrawal with the reserved UTXO by calling the
withdraw
operation again. Note the different flag on0xa3
.- System Assets:
- Operation:
withdraw
- Parameters: - None -
- Attributes:
-
0x20
:withdrawer
- Script hash of the user's address -
0xa1
:0x51
- Literal byte flag -
0xa3
:assetID
- Script hash of the asset ID to withdraw -
0xa4
:withdrawer
- Script hash of the user's address
-
- Witness
scripts
(signatures) required:- withdrawer
- contract:
{ invocationScript: '0000', verificationScript: '' }
- Operation:
- Old NEP-5 Tokens:
- Operation:
withdraw
- Parameters: - None -
- Attributes:
-
0x20
:contractHash
- Script hash of the Switcheo Exchange smart contract -
0xa1
:0x51
- Literal byte flag -
0xa2
:assetID
- Script hash of the asset ID to withdraw -
0xa4
:withdrawer
- Script hash of the user's address
-
- Witness
scripts
(signatures) required:- withdrawer
- contract:
{ invocationScript: '0000', verificationScript: '' }
- Operation:
- New NEP-5 Tokens (that do not require contract signature):
- Operation:
withdraw
- Parameters: - None -
- Attributes:
-
0xa1
:0x51
- Literal byte flag -
0xa2
:assetID
- Script hash of the asset ID to withdraw -
0xa4
:withdrawer
- Script hash of the user's address
-
- Witness
scripts
(signatures) required:- withdrawer
- Operation:
- System Assets:
- Assets will be withdrawn to wallet after the transactions are committed
- Find the offer hash of the offer you want to cancel
- Note: The smart contract only recognises offers (individual offers made by a maker) and do not have information on orders
- Find the hash of the offer to cancel via your transaction history which contains information of the offers you made on the blockchain via
makeOffer
- Announce a cancellation of the offer by calling the smart contract operation:
announceCancel
- Operation:
announceCancel
- Parameters:
- 0:
offerHash
: Offer hash of the offer to cancel
- 0:
- Attributes: - None -
- Witness
scripts
(signatures) required:- withdrawer
- Operation:
- Wait for the buffer time
- Do a cancellation transaction to cancel offer by calling the smart contract operation:
cancelOffer
- Operation:
cancelOffer
- Parameters:
- 0:
offerHash
: Offer hash of the offer to cancel
- 0:
- Attributes: - None -
- Witness
scripts
(signatures) required:- withdrawer
- Operation:
- Funds will be moved back to the contract balance and the withdrawal process can be done by following the manual withdraw steps in the preceding section