31Third.
  • 👋Introduction
    • About 31Third
    • Use cases
    • 0x Labs Collaboration
    • Architecture
    • Team
  • 🤝31Third API
    • Overview
    • Healthcheck
    • Assets
      • Wallet
      • Enzyme
    • Swap
      • Get started
      • price
      • quote
    • Basket Trade (m:n swap)
      • async
      • Wallet
      • Enzyme
      • SetProtocol
    • Refresh Quotes
    • RFQ
  • ⛓️Protocol
    • Overview
    • Contracts
      • BatchTrade
      • Owner Privilege
    • Prohibition
    • Audit
    • Statistics
      • Gas cost analysis
    • Fees
  • 📚Resources
    • FAQ
    • Start trading
    • Discord
    • Twitter
Powered by GitBook
On this page
  1. 31Third API
  2. Basket Trade (m:n swap)

Wallet

PreviousasyncNextEnzyme

Last updated 1 year ago

Calculate a rebalancing for a wallet. The minimal params are:

  • signer: Address

  • wallet: Address

  • baseEntries

  • baseEntries

🤝

Request a rebalancing for an arbitrary set of tokens

post

Sell tokens are passed with amounts, buy tokens are passed as percentage allocation

Header parameters
x-api-keystringOptional

31Third API key (Request via dev@31third.com)

chain-idstringOptional

Chain ID as hex string. (e.g.: 0x1 for Ethereum mainnet)

Body
signerstringRequired

The wallet that is used to sign the rebalancing and send it on-chain.

Example: 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B
maxDeviationFromTargetnumber · min: 0.001 · max: 1Optional

Maximum deviation from the target allocation. (0.01 = 1%)

Default: 0.005
maxSlippagenumber · max: 1Optional

Maximum allowed slippage for the calculated trades. (0.01 = 1%)

Default: 0.01
maxPriceImpactnumber · max: 1Optional

Max price impact for each calculated trade. (0.01 = 1%)

Default: 0.05
liquiditySourceSettingsall ofOptional

(COMING SOON) Settings for liquidity sources (DEXs, market makers, DeFi protocols)

batchTradebooleanOptional

Describes if batch trading should be enabled (if not trades can be executed one-by-one)

Default: trueExample: true
revertOnErrorbooleanOptional

Describes if the batch execution should revert if one trade fails. Otherwise the already positive executed trades are settled.

Default: true
skipBalanceValidationbooleanOptional

Describes if balance check should be skipped. (Can be useful for testing).

Default: false
failOnMissingPricePairbooleanOptional

If true, an exception is thrown, indicating that no price pair can be found for at least one of the tokens. (Only assets with a balance greater than 0 are considered.) If false, the rebalancing is still calculated without considering the tokens with no pairs.

Default: trueExample: true
asyncbooleanOptional

If true the rebalancing will be calculated asynchronously. The progress can be checked with the responded id

Default: falseExample: true
walletstringRequired

Wallet for which the rebalancing is calculated.

Example: 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B
Responses
200Success
application/json
post
POST /0.1/rebalancing/wallet HTTP/1.1
Host: 
Content-Type: application/json
Accept: */*
Content-Length: 865

{
  "signer": "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B",
  "baseEntries": [
    {
      "tokenAddress": "0xdac17f958d2ee523a2206206994597c13d831ec7",
      "amount": "69500000000000000"
    }
  ],
  "targetEntries": [
    {
      "tokenAddress": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
      "allocation": 0.2
    }
  ],
  "maxDeviationFromTarget": 0.005,
  "maxSlippage": 0.01,
  "maxPriceImpact": 0.05,
  "liquiditySourceSettings": {
    "decentralizedExchangeSettings": {
      "disable": true,
      "include": [
        "uniswap",
        "dodo",
        "cryptocom"
      ],
      "exclude": [
        "uniswap",
        "dodo",
        "cryptocom"
      ]
    },
    "marketMakerSettings": {
      "disable": true,
      "include": [
        "0x",
        "hashflow"
      ],
      "exclude": [
        "0x",
        "hashflow"
      ]
    },
    "deFiProtocolSettings": {
      "disable": true,
      "include": [
        "aave",
        "compound",
        "lido"
      ],
      "exclude": [
        "aave",
        "compound",
        "lido"
      ]
    }
  },
  "batchTrade": true,
  "revertOnError": true,
  "skipBalanceValidation": false,
  "failOnMissingPricePair": true,
  "async": true,
  "wallet": "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B"
}
200Success
{
  "id": "0096124c-19df-4459-8cbb-7615fdc7c157",
  "sellValueInUsd": 12345.67,
  "estimatedValueLossInUsd": 12.34,
  "estimatedReceiveValueInUsd": 12345.67,
  "minReceiveValueInUsd": 12325.67,
  "estimatedGasFees": "20000000000000000",
  "estimatedGasFeesInUsd": 23.45,
  "estimatedProtocolFeesInUsd": 23.45,
  "requiredAllowances": [
    {
      "token": {
        "id": "text",
        "address": "text",
        "name": "text",
        "symbol": "text",
        "imageUrl": "text",
        "decimals": 1,
        "coingeckoId": "text",
        "coinmarketcapId": "text",
        "coincapId": "text",
        "binanceSymbol": "text",
        "tags": [
          "text"
        ],
        "tokenType": 1,
        "allowanceType": 1,
        "enabled": true,
        "chain": {
          "name": "Ethereum",
          "identifier": "0x1",
          "enabled": true,
          "batchTradeSupported": true,
          "batchTradeAddress": "0x1ee8b39f09c5299526db65428ab2a8a23ebf08a7",
          "blockExplorerLink": "https://etherscan.io",
          "nativeTokenAddress": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
          "wrappedNativeTokenAddress": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
          "tokenHelperAddress": "0x6af90502f49E3B4151018F7aE82d10079c29Bc97",
          "portfolioEnabled": true
        },
        "sliderColor": "text",
        "queryPriceFromExchange": true,
        "mappingTokens": [
          "text"
        ],
        "mappingTokensOnly": true,
        "skipTradeValidation": true,
        "autoCreated": true
      },
      "allowanceTarget": "text",
      "neededAllowance": 1,
      "currentAllowance": 1,
      "resetNeeded": true
    }
  ],
  "trades": [
    {
      "id": "0096124c-19df-4459-8cbb-7615fdc7c157",
      "from": "0xdac17f958d2ee523a2206206994597c13d831ec7",
      "to": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
      "fromAmount": "100000000",
      "toAmount": "99500000",
      "minToReceive": "99000000",
      "toValueInEth": "69500000000000000",
      "fromValueInUsd": 100,
      "toValueInUsd": 99.5,
      "minToReceiveInUsd": 99,
      "calculatedLossPercentage": 0.005,
      "maxSlippage": 0.01,
      "price": 0.999955,
      "guaranteedPrice": 0.99,
      "previouslyRequiredTrades": [],
      "allowanceTarget": "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
      "estimatedFees": "5000000000000000",
      "txData": "0x6af479b200000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000005e68d620000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bdac17f958d2ee523a2206206994597c13d831ec70001f4a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000869584cd00000000000000000000000058ee0e1efcb86ad60d4df3c8a32b398887bb148b0000000000000000000000000000000000000000000000de6f27846963566719",
      "txHandler": "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
      "expirationTimestamp": "2025-05-17T05:43:40.417Z",
      "transactions": [
        "text"
      ]
    }
  ],
  "txHandler": "text",
  "txData": {},
  "txValue": 1,
  "tokensWithoutPricePair": [
    "0x3ed3b47dd13ec9a98b44e6204a523e766b225811"
  ],
  "expirationTimestamp": "2024-04-29T06:40:39.808Z",
  "executable": [
    "true"
  ]
}