Instant Withdrawal

Prerequisites

Before you run the instant‐withdrawal script, make sure you have everything in place:

  1. Install Node.js

  2. Create a project directory

    mkdir symmio-instant-withdrawal
    cd symmio-instant-withdrawal
  3. Initialize a new package.json

    npm init -y
  4. Install required NPM packages The script uses:

    • dotenv for environment‐variable loading

    • axios for HTTP calls

    • ethers for EVM wallet + RPC

    • web3 for the multi‐account wrapper calls

    Run:

    npm install dotenv axios ethers web3
  5. ABI files Make sure you have the two ABI JSON files in ./abi/:

    • DIAMOND_ABI.json (your Symmio Diamond)

    • MULTI_ACCOUNT_ABI.json (ABI for the deployed MultiAccount)

All contract addresses can be found here.

  1. Prepare your .env In the project root, create a .env file containing exactly the variables from our guide (see next section).

Once these steps are done, you’re ready to configure your environment variables and move on to the login & withdrawal flow.


Environment Variables

All Muon services can be found here.


Instant Withdrawal Flow

SIWE Login

Before you can call any of the Instant-Withdrawal API endpoints, you must authenticate yourself and prove ownership of your Ethereum wallet. We use Sign-In With Ethereum (SIWE) to:

  • Verify that you control the private key for your ACTIVE_ACCOUNT

  • Issue a short-lived JSON Web Token (JWT) that the API will accept as proof of identity on subsequent calls


Below is an example script that obtains the access token:


What You Get

  • accessToken (JWT): A bearer token you must include on every HTTP request:

  • Expiration: The token is valid until the exp claim in its payload. SIWE messages themselves can also include a custom expirationTime to limit replay window.

Lock & Fetch Fee Options

Before touching any on-chain collateral, you first ask the backend to compute and reserve your available instant-withdrawal policies for the exact amount you want. This call is purely off-chain—no transactions are sent, and no gas is spent—but it locks those policies for a short window (typically ~30 seconds) so you can finalize on-chain steps without worrying the fee or cooldown will change mid-flow.

HTTP Request

  • Query Parameters

    • account (string): your sub-account address (checksum)

    • amount (integer): the withdrawal amount in token units (wei for 6-decimals USDC! e.g. 1000000 for 1 USDC)

  • Headers

    • Authorization: Bearer <accessToken> (from your SIWE login)

  • Body

    • Empty. (Axios will send {} if you pass an empty object—no other fields required.)


Example Code

This must be called with the sub-account address

Sample Response


Picking your Policy

Of this set of options, you can pick the policy with the lowest cooldown like this:

Deallocating Funds

Before you can instantly withdraw, you must deallocate (i.e. free) the amount of collateral you previously allocated to trading. Symmio requires a uPNL signature from Muon to verify that you maintain sufficient margin for your currently open positions; this happens off-chain via a Muon oracle call.

Flow

  1. Fetch a Muon signature that attests to your current uPnl.

  2. Format that signature into the SingleUpnlSig struct the contract expects.

  3. ABI-encode the deallocate(uint256 amount, SingleUpnlSig upnlSig) call.

  4. Wrap it in your multi-account proxy (_call) so that msg.sender is your sub-account.

  5. Estimate gas (with a buffer) and send the transaction (paid by your EOA).

Sample Script

Implementation

Transfer to Bridge On-Chain

After freeing your collateral, the next on-chain step is to transfer that free balance into the Instant-Withdrawal bridge, bypassing any further cooldown. This creates a bridge transaction from which you will then select your fee policy.

Sample Script

When you call the wrapped _call(...).send(), the Symmio Diamond contract will emit a TransferToBridge event that includes your new transactionId. This is the ID you’ll need in the final step to select your fee policy.

Event signature

Fetching Pending Fee Policies

After your on-chain bridge transaction is mined, you can once again retrieve the exact fee/cooldown options that were locked earlier by your /fee-options call. These are exposed via a dedicated endpoint:

GET /v1/pending-fee-policy/{account}

Sample Script

Submit Fee Policy Selection

With your on‐chain bridge transaction done and your fastest policy chosen, the final step is to tell the backend “yes, I agree to pay this fee after this cooldown.” The server will validate your choice, call the on‐chain selectFeePolicyForBridge action, and schedule processWithdrawal(bridgeId) for you.

Implementation

Reference Implementation

This repository contains a python script showcasing the full flow for Instant Withdrawal.

Last updated