Variational Docs
HomeDiscordTwitterBlog
  • Variational Protocol
    • About Variational
    • Peer-to-peer vs DEX
    • Roadmap
    • Key Concepts
      • Trading via RFQ
      • Settlement Pools
      • Margin
      • Slippage
      • Leverage
      • Liquidation
      • Mark price vs index price vs quote price
      • Open Interest & Funding Rates
      • Fully Diluted Valuation (FDV)
      • Fees
      • Market vs. Limit Orders
      • Take Profit & Stop Loss
    • $VAR Token
    • Media Kit
    • Official Links
    • FAQ
    • Getting Help (Support)
  • Variational Omni
    • About Omni
    • Getting Started with Omni
    • Getting Started With Omni (Testnet)
    • Omni Liquidity Provider (OLP)
    • Listings
    • Risk Limits
  • Automatic Deleveraging | Counterparty Liquidation
  • Variational Pro
    • About Pro
  • Technical Documentation
    • Technical Overview
      • Authentication
      • Deposits
      • Withdrawals
      • Trades
    • Derivative Specifications
      • Perpetual Futures
      • Settlement
    • API
      • SDKs
      • Quickstart and Tutorials
        • API Trading Prerequisites and Setup
        • Settlement Pool Deposit Tutorial
        • Taker (RFQ Submitter) Tutorial
        • Maker (RFQ Responder) Tutorial
      • Endpoints
      • Data Models
      • Headers
      • Pagination
      • Rate Limits
      • Authentication
    • Contracts and ABIs
    • Security and Audits
    • Partners
  • Legal
    • Terms of Service
    • Privacy Policy
    • Restricted Persons
  • ARCHIVE
    • Testnet Trading Competition #1 Leaderboard
    • Testnet Trading Competition #2 Leaderboard
    • Testnet Trading Competition #3 Leaderboard
Powered by GitBook
On this page
  • Create a Settlement Pool
  • Make A Deposit
  • Verify
  1. Technical Documentation
  2. API
  3. Quickstart and Tutorials

Settlement Pool Deposit Tutorial

PreviousAPI Trading Prerequisites and SetupNextTaker (RFQ Submitter) Tutorial

Last updated 5 months ago

This tutorial relies on programming context established in . Settlement Pools can either be created ahead of time with specific counterparties, or created at the time of trading as part of the clearing flow.

Create a Settlement Pool

If you need to create a settlement pool with a new counterparty, or need another pool with different margin parameters, here's how you create one via the API:

from variational import MarginMode

other_company_id = "1ebc7ece-093e-42aa-8cdf-028ccb1fc68a"

margin_params = {
    "margin_mode": MarginMode.SIMPLE,
    "params": {
        "liquidation_penalty": "0.1",
        "auto_liquidation": True,
        "asset_params": {},
        "default_asset_param": {
            "futures_initial_margin": "0.02",
            "futures_maintenance_margin": "0.01",
            "futures_leverage": "1000000000",
            "option_initial_margin": "0.15",
            "option_initial_margin_min": "0.1",
            "option_maintenance_margin": "0.075",
        },
    }
}
new_pool = client.create_settlement_pool(
    pool_name="Tutorial pool",
    company_other=other_company_id,
    creator_params=margin_params,
    other_params=margin_params,
).result
print(json.dumps(new_pool, indent=2))
Output
{
  "company_id": "f58b3d2f-b5a6-488d-b8a9-dc2b1f782be8",
  "data": {
    "address": null,
    "name": "Tutorial pool",
    "created_at": "2024-04-03T17:35:23.710289Z",
    "company_creator": "f58b3d2f-b5a6-488d-b8a9-dc2b1f782be8",
    "positions": [],
    "status": "pending",
    "confirmed_by_transaction_id": null,
    "parties": [
      {
        "company": "f58b3d2f-b5a6-488d-b8a9-dc2b1f782be8",
        "created_at": "2024-04-03T17:35:23.710289Z",
        "address": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
        "margin_usage": {
          "balance": "0",
          "margin_params": {
            "margin_mode": "simple",
            "params": {
              "asset_params": {},
              "auto_liquidation": true,
              "default_asset_param": {
                "futures_initial_margin": "0.02",
                "futures_leverage": "20000",
                "futures_maintenance_margin": "0.01",
                "option_initial_margin": "0.15",
                "option_initial_margin_min": "0.1",
                "option_maintenance_margin": "0.075"
              },
              "liquidation_penalty": "0.1"
            }
          },
          "margin_usage": {
            "initial_margin": "0",
            "maintenance_margin": "0"
          },
          "max_withdrawable_amount": "0"
        },
        "status": "pending",
        "confirmed_by_transaction_id": null
      },
      {
        "company": "1ebc7ece-093e-42aa-8cdf-028ccb1fc68a",
        "created_at": "2024-04-03T17:35:23.710289Z",
        "address": "0xa0ee7a142d267c1f36714e4a8f75612f20a79720",
        "margin_usage": {
          "balance": "0",
          "margin_params": {
            "margin_mode": "simple",
            "params": {
              "asset_params": {},
              "auto_liquidation": true,
              "default_asset_param": {
                "futures_initial_margin": "0.02",
                "futures_leverage": "20000",
                "futures_maintenance_margin": "0.01",
                "option_initial_margin": "0.15",
                "option_initial_margin_min": "0.1",
                "option_maintenance_margin": "0.075"
              },
              "liquidation_penalty": "0.1"
            }
          },
          "margin_usage": {
            "initial_margin": "0",
            "maintenance_margin": "0"
          },
          "max_withdrawable_amount": "0"
        },
        "status": "pending",
        "confirmed_by_transaction_id": null
      }
    ]
  },
  "pool_id": "6b2120ac-2aaf-40bc-b369-75d7e231c529"
}

Note that a new pool is always created in the pending status. Before you can deposit funds, it needs to be created on-chain and transition to open status. This will happen automatically, but can take a few seconds.

Use the helper to wait until the settlement pool becomes ready:

pool = poller.wait_for_settlement_pool(new_pool["pool_id"])

Make A Deposit

deposit_amount = 10000

permits.sign_and_submit_decimal(
    pool_address=pool['data']['address'],
    allowance=str(deposit_amount)
)

Next, you initiate a deposit transfer for the approved amount (or less):

from variational import TransferType
new_transfer = client.create_transfer(
    asset="USDC",
    qty=str(deposit_amount),
    target_pool_location=pool["pool_id"],
    # allocate these funds for trading with this counterparty
    counterparty=other_company_id,  
    transfer_type=TransferType.DEPOSIT,
).result
print(json.dumps(new_transfer, indent=2))
Output
{
  "asset": "USDC",
  "company": "f58b3d2f-b5a6-488d-b8a9-dc2b1f782be8",
  "created_at": "2024-04-03T17:40:49.491519Z",
  "id": "5e3d6f7c-a787-40c2-a4c1-b6f35eb188a1",
  "oracle_request_id": null,
  "parent_quote_id": null,
  "qty": "10000",
  "reference_instrument": null,
  "rfq_id": null,
  "status": "pending",
  "target_pool_location": "6b2120ac-2aaf-40bc-b369-75d7e231c529",
  "counterparty": "1ebc7ece-093e-42aa-8cdf-028ccb1fc68a",
  "transfer_type": "deposit"
}

Note that a transfer is created in pending status. Use the helper to wait until the deposit happens on-chain and the status changes to confirmed:

transfer = poller.wait_for_transfer(transfer['id'])

Verify

You can confirm that the deposit has been completed successfully by checking the settlement pool's balance:

pool = client.get_settlement_pools(id=pool["pool_id"]).result[0]
print(json.dumps(pool, indent=2))
Output
{
  "company_id": "f58b3d2f-b5a6-488d-b8a9-dc2b1f782be8",
  "data": {
    "address": "0x41574c5b15d67f95c7037a19cb7620c2643f2a98",
    "name": "Tutorial pool",
    "created_at": "2024-04-03T17:35:23.710289Z",
    "company_creator": "f58b3d2f-b5a6-488d-b8a9-dc2b1f782be8",
    "positions": [],
    "status": "open",
    "confirmed_by_transaction_id": "0x8681959c118ea67dff6272da137aacdce4cdb87aaf06cae380842f19b8b0ac2b",
    "parties": [
      {
        "company": "f58b3d2f-b5a6-488d-b8a9-dc2b1f782be8",
        "created_at": "2024-04-03T17:35:23.710289Z",
        "address": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
        "margin_usage": {
          "balance": "10000",
          "margin_params": {
            "margin_mode": "simple",
            "params": {
              "asset_params": {},
              "auto_liquidation": true,
              "default_asset_param": {
                "futures_initial_margin": "0.02",
                "futures_leverage": "20000",
                "futures_maintenance_margin": "0.01",
                "option_initial_margin": "0.15",
                "option_initial_margin_min": "0.1",
                "option_maintenance_margin": "0.075"
              },
              "liquidation_penalty": "0.1"
            }
          },
          "margin_usage": {
            "initial_margin": "0",
            "maintenance_margin": "0"
          },
          "max_withdrawable_amount": "10000"
        },
        "status": "confirmed",
        "confirmed_by_transaction_id": "0x8681959c118ea67dff6272da137aacdce4cdb87aaf06cae380842f19b8b0ac2b"
      },
      {
        "company": "1ebc7ece-093e-42aa-8cdf-028ccb1fc68a",
        "created_at": "2024-04-03T17:35:23.710289Z",
        "address": "0xa0ee7a142d267c1f36714e4a8f75612f20a79720",
        "margin_usage": {
          "balance": "0",
          "margin_params": {
            "margin_mode": "simple",
            "params": {
              "asset_params": {},
              "auto_liquidation": true,
              "default_asset_param": {
                "futures_initial_margin": "0.02",
                "futures_leverage": "20000",
                "futures_maintenance_margin": "0.01",
                "option_initial_margin": "0.15",
                "option_initial_margin_min": "0.1",
                "option_maintenance_margin": "0.075"
              },
              "liquidation_penalty": "0.1"
            }
          },
          "margin_usage": {
            "initial_margin": "0",
            "maintenance_margin": "0"
          },
          "max_withdrawable_amount": "0"
        },
        "status": "confirmed",
        "confirmed_by_transaction_id": "0x8681959c118ea67dff6272da137aacdce4cdb87aaf06cae380842f19b8b0ac2b"
      }
    ]
  },
  "pool_id": "6b2120ac-2aaf-40bc-b369-75d7e231c529"
}

In order to deposit USDC into the pool, you need to sign and submit a spending approval:

Prerequisites and Setup
ERC-2612