LogoLogo
  • Overview
    • Introduction
    • Table of Contents
  • Token Information
    • Symmio Foundation
  • Protocol Architecture
    • Protocol Introduction
    • Technical Documentation
      • Building an Application with SYMM
        • Introduction and Diamond Explainer
        • Querying Info from the SYMM Diamond
        • MultiAccount
        • Creating an Account and Depositing Funds
        • Sending a Quote
        • Closing a Quote
        • Instant Trading
          • Instant Login (EOA)
          • Instant Login (Account Abstraction)
          • Sending a Quote (Instant Open)
          • Sending a Quote (Instant Close)
        • Frequently Used Queries
      • Solver Docs
        • Solver Docs (github)
        • Solver Implementation Guide (High Level Overview)
        • Building a Solver on SYMMIO
          • 1. Intent Creation
          • 2. Seeing the Intent
          • 3. Hedging Off-Chain
          • 4. Opening/Closing a Position On-Chain
          • Creating the APIs
            • GET Contract Symbols
            • GET Open Interest
            • GET Notional Cap
            • GET Price Range
            • GET Error Codes
            • GET Get Locked Params
            • GET Get Funding Info
            • POST Position State
          • Solver Flow Summary Example
          • Recommended Architecture for Solvers
          • Glossary
        • Conditional Orders Handler
        • Rasa Solver TP/SL Implementation
        • Instant Trading
          • Instant Trading (Solvers)
          • Rasa Instant Trading Implementation
          • Instant Trading Condition Checks
        • Fetching Gas Prices Script
        • How to Add a Market as a Solver
        • Verifying Account Abstracted Instant Actions (ERC-4337)
      • Frontend Docs
        • Setting up a Frontend with SYMMIO
        • Frontend SDK Setup Guide
        • MultiAccount Deployment Guide
        • Instant Trading (Frontends)
          • Account Abstracted Instant Actions (Frontends)
        • Implement a Trading Bot on Symmio (OLD)
          • Setup
          • Creating a Sub-Account
          • Minting Collateral Tokens (Optional)
          • Depositing and Allocating Tokens
          • Obtaining Muon Signatures
          • Sending a Quote
          • Monitoring Price for Execution
      • Contract Docs
        • SYMMIO CORE v0.82
        • Contracts Documentation 0.8.2
          • Main Flow
          • The SYMM Diamond
          • Facets
            • Account Facet
            • Control Facet
            • Funding Rate Facet
            • PartyA Facet
            • PartyB Facet
            • Liquidation Facet
            • View Facet
          • MultiAccount
            • PartyA
            • PartyB
          • SYMM App (Muon)
            • LibMuon
            • MuonStorage
        • Contracts Documentation 0.8.3
          • Facets
            • Control Facet
            • Account Facet
            • PartyA Facet
            • PartyB Facet
            • View Facet
            • Bridge Facet
            • Liquidation Facet (Implementation)
          • Modified Events
          • New Events
          • MuonStorage
        • Contracts Documentation 0.8.4
          • Main Flow (0.8.4)
          • The SYMM Diamond (0.8.4)
          • Facets
            • Account Facet (0.8.4)
            • Bridge Facet (0.8.4)
            • Control Facet (0.8.4)
            • Force Actions Facet (0.8.4)
            • Funding Rate Facet (0.8.4)
            • Liquidations Facet (0.8.4)
            • PartyA Facet (0.8.4)
            • PartyB Group Actions Facet (0.8.4)
            • PartyB Quote Actions Facet (0.8.4)
            • PartyB Position Actions Facet (0.8.4)
            • Settlement Facet (0.8.4)
            • View Facet (0.8.4)
          • MultiAccount (0.8.4)
            • SymmioPartyA
            • SymmioPartyB
          • SYMM App (Muon)
            • LibMuon (0.8.4)
            • MuonStorage (0.8.4)
      • Contract Addresses / Solver Endpoints
        • Mantle
        • Mode
        • IOTA
        • Base
        • BSC
        • Arbitrum
        • Polygon
        • Berachain
        • Solver Endpoints and Addresses
          • Perps Hub
          • Rasa Capital
          • Zenith
      • How to Query our Contracts
      • Muon API Queries
      • Solver Error Codes
      • Interacting with SYMMIO Contracts
    • Protocol higher level architecture
      • 12-Hour Fraud Proof Window
      • PartyB
      • Solver Settings
      • Max Leverage
      • Maintenance Margin (CVA) Calculations
    • Symmio Whitepaper
  • Building on Symmio
    • Builders introduction
    • Solving for Symmio
      • Solver documentation
      • Solver - Example Flow
    • Trading Fees
      • Perps - Settlement Costs
      • Pair Trading - Settlement costs
    • Exchanges (Frontends)
      • Frontend Introduction
      • SDK - SYMM client
      • Trade on Symmio
  • Legal & Brand & Security
    • Security (Audits / Bugbounty)
      • Bug bounty / Coverage
        • How to contact ?
      • Audits
        • SYMM - V0.8 - 0.81
          • Sherlock Audit - Jun 15, 2023
          • Smart State - Jul 2, 2023
        • SYMM - 0.82
          • Sherlock Audit -Aug 30, 2023
        • SYMM - 0.83
          • Sherlock Audit - Jun 17, 2024
        • SYMM - 0.84
          • Sherlock Audit - Oct 3, 2024
        • Vaults
          • Sherlock Audit - Jan 2, 2024
    • Terms of Service & Licensing
      • TRADEMARK & COPYRIGHT NOTICE
      • CONTACT US
      • TERMS OF SERVICE
      • FRONTEND LICENSE
        • Frontend Modifications
        • Frontend Use Grants
      • CONTRACT LICENSE
        • Contract Use Grants
        • Contract Modifications
    • Brand - Assets Logos
Powered by GitBook
LogoLogo

All rights to the people (c) 2023 Symmetry Labs A.G.

On this page
  • Instant Login for Instant Open/Close
  • Flow Overview
  • Delegating Access
  1. Protocol Architecture
  2. Technical Documentation
  3. Building an Application with SYMM
  4. Instant Trading

Instant Login (EOA)

PreviousInstant TradingNextInstant Login (Account Abstraction)

Last updated 1 month ago

Instant Login for Instant Open/Close

Before you can perform instant open or instant close actions, your sub‑account must delegate access to the solver (Party B) for these functions. Once delegated, you must obtain an access token through a two-step SIWE (Sign-In With Ethereum) login flow. This process ensures that you are authorized to execute instant actions and that your request includes a validated expiration date.

Flow Overview

  1. Delegate Access: First, delegate access from your sub‑account to the solver’s address so that they can call functions (such as open, request to close, or cancel close) on your behalf.

  2. Fetch a Nonce: Query the hedger’s endpoint using your sub‑account address. The nonce ensures the uniqueness of your SIWE message and prevents replay attacks.

  3. Build and Sign the SIWE Message: Construct a SIWE message that includes your wallet address, the nonce, a statement (the sub-account), and timestamps (issued and expiration). This message must be signed by your wallet to confirm your intent.

  4. Send Login Request: Submit your signed SIWE message to the hedger’s endpoint. Upon successful verification, you will receive an access token. This token is then used for subsequent instant open or close operations.

Delegating Access

To enable instant actions on the frontend, users must delegate specific functions to solvers so they can perform actions on the user's behalf without requiring signatures for each request.

Front-ends should ensure that the following functions are delegated to the solver addresses through the delegateAccesses() method on the contract, passing these function signatures.:

  • sendQuote: 0x7f2755b2

  • sendQuoteWithAffiliate: 0x40f1310c

  • requestToClosePosition: 0x501e891f

  • requestToCancelQuote: 0xa8ffc7ab

  • requestToCancelCloseRequest: 0xa63b9363

  • allocate: 0x90ca796b

After Delegating Access you can proceed with the login process.

Example Script

Below is a Node.js script (using ethers and axios) that demonstrates the nonce fetch and instant login flow:

Delegation of Access: Ensure that your sub‑account has already delegated access to the solver for instant actions before starting the login flow.

// Load environment variables from a .env file
require("dotenv").config();

// Import required libraries: ethers for Ethereum utilities, and axios for HTTP requests
const { ethers } = require("ethers");
const axios = require("axios");

// Retrieve the private key from environment variables
const PRIVATE_KEY = process.env.PRIVATE_KEY;

// Convert the active account address from the env into a checksummed Ethereum address.
// Using ethers.getAddress ensures the address format is correct. This is the sub-account.
const activeAccount = ethers.getAddress(process.env.activeAccount); 
const wallet = new ethers.Wallet(PRIVATE_KEY);

// Define the base URL of the authentication (solver) server. In this example we'll use Rasa on Base
const SOLVER_BASE_URL = "https://base-hedger82.rasa.capital";
const DOMAIN = "localhost"; 
const ORIGIN = "http://localhost:3000";
const CHAIN_ID = 8453;
const LOGIN_URI = `${SOLVER_BASE_URL}/login`; 
const ISSUED_AT = new Date().toISOString(); 

const EXPIRATION_DATE = new Date(Date.now() + (24 * 60 * 60 * 10)).toISOString(); //Long-dated expiration

//Fetching Nonce from Solver
async function getNonce(address) {
  const url = `${SOLVER_BASE_URL}/nonce/${address}`;
    const { data } = await axios.get(url);
  return data.nonce; 
}

// -----------------------------
// MAIN EXECUTION BLOCK
// -----------------------------
(async function main() {
  try {
    console.log(`\n[1/4] Wallet Address: ${wallet.address}`); 
    console.log(`[1.5/4] Active Account (Checksum): ${activeAccount}`);
    
    // Fetch the nonce for the active account from the server
    const nonce = await getNonce(activeAccount);
    console.log(`[2/4] Got nonce: ${nonce}`);
    
    // Build the SIWE (Sign-In With Ethereum) message using the provided parameters.
    // Note that the message is signed using the wallet address, while the active account is used in the statement.
    const siweMessage = buildSiweMessage({
      domain: DOMAIN,
      address: wallet.address,        
      statement: `msg: ${activeAccount}`, 
      uri: LOGIN_URI,
      version: "1",
      chainId: CHAIN_ID,
      nonce,
      issuedAt: ISSUED_AT,
      expirationTime: EXPIRATION_DATE,
    });

    console.log("\n[3/4] SIWE message to sign:\n", siweMessage);

    // Sign the SIWE message using the wallet's private key
    const signature = await wallet.signMessage(siweMessage);
    console.log("\nSignature:", signature);

    // Construct the request body to send to the login endpoint, including the signature and nonce
    const body = {
      account_address: activeAccount, 
      expiration_time: EXPIRATION_DATE,
      issued_at: ISSUED_AT,
      signature,
      nonce
    };

    // Define HTTP headers including content type and origin (used for CORS validation on the server)
    const headers = {
      "Content-Type": "application/json",
      Origin: ORIGIN,
      Referer: ORIGIN, 
    };
    
    console.log("\n[4/4] Sending login request...");
    
    // Send the login request (POST) to the server with the constructed body and headers
    const response = await axios.post(
      `${SOLVER_BASE_URL}/login`,
      body,
      { headers }
    );
    
    console.log("Login response:", response.data);

  } catch (err) {
    console.error("Error in SIWE login flow:", err.response?.data || err.message);
  }
})();

// -----------------------------
// UTILITY FUNCTION: buildSiweMessage
// -----------------------------
// Constructs a SIWE (Sign-In With Ethereum) message following the EIP-4361 standard.
// For more details, see: https://eips.ethereum.org/EIPS/eip-4361
function buildSiweMessage({
  domain,
  address,
  statement,
  uri,
  version,
  chainId,
  nonce,
  issuedAt,
  expirationTime
}) {
  return `${domain} wants you to sign in with your Ethereum account:
${address}

${statement}

URI: ${uri}
Version: ${version}
Chain ID: ${chainId}
Nonce: ${nonce}
Issued At: ${issuedAt}
Expiration Time: ${expirationTime}`;
}

/* 
Example SIWE message output:
---------------------------------------------
localhost wants you to sign in with your Ethereum account:
0x3B5aC601c7bB74999AB3135fa43cbDBc6aB74570

msg: 0xb1936f6158eC7906C37e82A8230bf545aF29102F

URI: https://base-hedger82.rasa.capital/login
Version: 1
Chain ID: 8453
Nonce: zp0JU2TX6N0
Issued At: 2025-03-31T17:02:46.736Z
Expiration Time: 2025-03-31T17:17:10.736Z
*/

Upon successful login, the response includes an access token. This token must be attached in the headers of any instant open or close requests that you subsequently send.

MultiAccount
nonce
/login