Skip to content

Manual Withdraws (Direct from V2 Smart Contract)

Henry Chua edited this page Aug 20, 2018 · 5 revisions

Preface

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.

With the advent of V2 contract the order books are now 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.

Overview

Manual Withdrawal

  1. 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)
  2. Wait for the buffer time announceDelay
  3. Reserve UTXOs 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 in 0xa2 vs 0xa3, as well as the value for 0x20, 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
    • 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: '' }
  4. Complete withdrawal with the reserved UTXO by calling the withdraw operation again. Note the different flag on 0xa3.
    • 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: '' }
    • 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: '' }
    • 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
  5. Assets will be withdrawn to wallet after the transactions are committed

Manual Offer Cancellation

  1. 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
  2. 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
    • Attributes: - None -
    • Witness scripts (signatures) required:
      • withdrawer
  3. Wait for the buffer time
  4. 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
    • Attributes: - None -
    • Witness scripts (signatures) required:
      • withdrawer
  5. 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