# Enzyme

Calculate a rebalancing for an Enzyme vault. The minimal params are:

* signer: Address
* vault: Address
* baseEntries (If an empty array is passed all vault tokens are considered as base allocation)
* targetEntries

## POST /1.3/rebalancing/enzyme

> Request a rebalancing for an enzyme vault with a target allocation.

```json
{"openapi":"3.0.0","info":{"title":"31Third Trading API","version":"1.3"},"tags":[{"name":"rebalancing/enzyme","description":"Calculate rebalancings for Enzyme vaults"}],"paths":{"/1.3/rebalancing/enzyme":{"post":{"operationId":"RebalancingEnzymeController_calculateOptimalEnzymeRebalancing","summary":"Request a rebalancing for an enzyme vault with a target allocation.","parameters":[{"name":"x-api-key","in":"header","description":"31Third API key (Request via dev@31third.com)","schema":{"type":"string"}},{"name":"chain-id","in":"header","description":"Chain ID as hex string. (e.g.: 0x1 for Ethereum mainnet)","schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RebalancingEnzymeVaultQueryDto"}}}},"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/RebalancingResponseDto"}}}}},"tags":["rebalancing/enzyme"]}}},"components":{"schemas":{"RebalancingEnzymeVaultQueryDto":{"type":"object","properties":{"signer":{"type":"string","description":"The wallet that is used to sign the rebalancing and send it on-chain."},"baseEntries":{"description":"List of base entries (token and amount). (If an empty array is passed all vault tokens are considered as base allocation. Tokens with a value < $0.01 are ignored.)","type":"array","items":{"$ref":"#/components/schemas/RebalancingAmountEntryDto"}},"targetEntries":{"description":"List of target entries (token and allocation)","type":"array","items":{"$ref":"#/components/schemas/RebalancingAllocationEntryDto"}},"maxDeviationFromTarget":{"type":"number","description":"Maximum deviation from the target allocation. (0.01 = 1%)","minimum":0.001,"default":0.005,"maximum":1},"maxSlippage":{"type":"number","description":"Maximum allowed slippage for the calculated trades. (0.01 = 1%)","minimum":0,"default":0.005,"maximum":1},"maxPriceImpact":{"type":"number","description":"Max price impact for the calculated basket trade. (0.01 = 1%)","minimum":0,"default":0.01,"maximum":1},"priceImpactExceedsError":{"type":"boolean","description":"If true an error is returned if the price impact is exceeded. Otherwise an issue (warning) is added to the response. Defaults to false.","default":false},"minExpirySec":{"type":"number","description":"Min quote expiry. (in seconds)\nRFQ/OTC quotes from market makers have hard expiries between 40-90 seconds. If minExpiry is set higher then MM expiries these MMs are excluded. (Keep in mind that MM pricing might be better than DEX pricing, especially if quantity is high)","minimum":10,"default":35,"maximum":120},"minTradeValue":{"type":"number","description":"Min trade value. (in USD)\nThe smart order router ignores potential trades with a value smaller than minTradeValue. Super small value trades often lead to execution issues, therefore we skip trades smaller than $1 by default.","minimum":0,"default":1},"liquiditySourceSettings":{"description":"(COMING SOON) Settings for liquidity sources (DEXs, market makers, DeFi protocols)","deprecated":true,"allOf":[{"$ref":"#/components/schemas/LiquiditySourceSettingsDto"}]},"liquiditySourceConfig":{"description":"Configure liquidity sources. Whitelisting or blacklisting is available on a source level but also on a type level.","allOf":[{"$ref":"#/components/schemas/LiquiditySourceConfigDto"}]},"batchTrade":{"type":"boolean","description":"Describes if batch trading should be enabled (if not trades can be executed one-by-one)","default":true},"revertOnError":{"type":"boolean","description":"Describes if the batch execution should revert if one trade fails. Otherwise the already positive executed trades are settled.","default":true},"skipBalanceValidation":{"type":"boolean","description":"Describes if balance check should be skipped. (Can be useful for testing).","default":false},"failOnMissingPricePair":{"type":"boolean","description":"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":false},"async":{"type":"boolean","description":"If true the rebalancing will be calculated asynchronously. The progress can be checked with the responded id","default":false},"simulationTxOrigin":{"type":"string","description":"[FOR TENDERLY SIMULATION] Address that should be used instead of <code>signer</code>. Can be useful for Tenderly simulation if simulating an Enzyme vault you're not the owner of."},"vault":{"type":"string","description":"Vault for which the rebalancing is calculated."},"testnet":{"type":"boolean","description":"Activate testnet. (Just for Polygon)","default":false}},"required":["signer","baseEntries","targetEntries","simulationTxOrigin","vault"]},"RebalancingAmountEntryDto":{"type":"object","properties":{"tokenAddress":{"type":"string","description":"Address of the token in base allocation. (Ethereum is passed as \"ETH\" or \"0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\".)"},"amount":{"type":"string","description":"Amounts of the base token to sell (in WEI)"}},"required":["tokenAddress","amount"]},"RebalancingAllocationEntryDto":{"type":"object","properties":{"tokenAddress":{"type":"string","description":"Address of the token in target allocation. (Ethereum is passed as \"ETH\" or \"0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\")."},"allocation":{"type":"number","description":"Allocation of the token in percent summing up to 1.00. (0.01 = 1%)"}},"required":["tokenAddress","allocation"]},"LiquiditySourceSettingsDto":{"type":"object","properties":{"decentralizedExchangeSettings":{"description":"Settings for DEXs","deprecated":true,"allOf":[{"$ref":"#/components/schemas/DecentralizedExchangeSettingsDto"}]},"marketMakerSettings":{"description":"Settings for market makers","deprecated":true,"allOf":[{"$ref":"#/components/schemas/MarketMakerSettingsDto"}]},"deFiProtocolSettings":{"description":"Settings for DeFi protocols","deprecated":true,"allOf":[{"$ref":"#/components/schemas/DeFiProtocolSettings"}]}}},"DecentralizedExchangeSettingsDto":{"type":"object","properties":{"disable":{"type":"boolean","description":"Describes if decentralized exchange liquidity (e.g.: Uniswap, SushiSwap) should be disabled","default":false},"include":{"description":"Whitelisting. Just include the given sources. (Cannot be combined with <code>disable</code> set to <code>true</code> or <code>exclude</code>)","default":[],"type":"array","items":{"type":"string"}},"exclude":{"description":"Blacklisting. Exclude the given sources. (Cannot be combined with <code>disable</code> set to <code>true</code> or <code>include</code>)","default":[],"type":"array","items":{"type":"string"}}}},"MarketMakerSettingsDto":{"type":"object","properties":{"disable":{"type":"boolean","description":"Describes if market maker liquidity (e.g.: 0x RFQ, Hashflow) should be disabled","default":false},"include":{"description":"Whitelisting. Just include the given sources. (Cannot be combined with <code>disable</code> set to <code>true</code> or <code>exclude</code>)","default":[],"type":"array","items":{"type":"string"}},"exclude":{"description":"Blacklisting. Exclude the given sources. (Cannot be combined with <code>disable</code> set to <code>true</code> or <code>include</code>)","default":[],"type":"array","items":{"type":"string"}}}},"DeFiProtocolSettings":{"type":"object","properties":{"disable":{"type":"boolean","description":"Describes if DeFi protocols (e.g.: Aave, Compound) should be disabled","default":false},"include":{"description":"Whitelisting. Just include the given sources. (Cannot be combined with <code>disable</code> set to <code>true</code> or <code>exclude</code>)","default":[],"type":"array","items":{"type":"string"}},"exclude":{"description":"Blacklisting. Exclude the given sources. (Cannot be combined with <code>disable</code> set to <code>true</code> or <code>include</code>)","default":[],"type":"array","items":{"type":"string"}}}},"LiquiditySourceConfigDto":{"type":"object","properties":{"types":{"description":"(WIP) Liquidity sources types","type":"array","items":{"type":"string"}},"sources":{"description":"Configuration allows three strategies: empty, include or exclude.\n - Empty: all sources are enabled. \n - Include (Whitelisting): only the given sources are enabled. \n - Exclude (Blacklisting): all sources except the given ones are enabled.","oneOf":[{"$ref":"#/components/schemas/IncludeLiquiditySourcesDto"},{"$ref":"#/components/schemas/ExcludeLiquiditySourcesDto"}]}}},"IncludeLiquiditySourcesDto":{"type":"object","properties":{"include":{"type":"object","description":"Sources to include. Default for all others is disabled. (Whitelisting)","additionalProperties":{"$ref":"#/components/schemas/SubLiquiditySourceSelectionDto"}}},"required":["include"]},"SubLiquiditySourceSelectionDto":{"type":"object","properties":{"subSources":{"type":"object","description":"Map of sub-source identifiers to an empty object marker, signifying selection.","additionalProperties":{"type":"object","description":"An empty object {} marker."}}}},"ExcludeLiquiditySourcesDto":{"type":"object","properties":{"exclude":{"type":"object","description":"Sources to exclude. Default for all others is enabled. (Blacklisting)","additionalProperties":{"$ref":"#/components/schemas/SubLiquiditySourceSelectionDto"}}},"required":["exclude"]},"RebalancingResponseDto":{"type":"object","properties":{"id":{"type":"string","description":"Unique ID of the calculated rebalancing."},"creationDate":{"format":"date-time","type":"string","description":"Rebalancing creation timestamp"},"baseValueInUsd":{"type":"number","description":"Total value of assets in the rebalancing base allocation. (in USD)"},"sellValueInUsd":{"type":"number","description":"The proportion of value that is taken out for trades, meaning sold. (in USD)"},"estimatedValueLossInUsd":{"type":"number","description":"Estimated loss of total portfolio value. (in USD; fees are already included in this value)"},"estimatedTargetValueInUsd":{"type":"number","description":"Estimated total value of the rebalancing target allocation. (in USD; fees are already included in this value)"},"estimatedReceiveValueInUsd":{"type":"number","description":"Estimated value of assets received after all trades. (in USD; fees are already included in this value)"},"minReceiveValueInUsd":{"type":"number","description":"Minimal total portfolio value after the rebalancing. (in USD; slippage and fees are included in this value)"},"estimatedImpact":{"type":"number","description":"Estimated impact. (0.01 = 1%; fees are already included in this value)"},"maxImpact":{"type":"number","description":"Maximal impact. (0.01 = 1%; slippage and fees are included in this value)"},"estimatedGasUnits":{"format":"int64","type":"integer","description":"Estimated gas units for this trade. (in WEI)"},"suggestedGasPrice":{"format":"int64","type":"integer","description":"Suggested gas price [LOW/MARKET/AGGRESSIVE] fetched from a block explorer (e.g. Etherscan). (in WEI)"},"estimatedGasFees":{"format":"int64","type":"integer","description":"Estimated gas fees for the rebalancing. (in WEI)"},"estimatedGasFeesInUsd":{"type":"number","description":"Estimated gas fees for the rebalancing. (in USD)"},"estimatedProtocolFeesInUsd":{"type":"number","description":"Estimated protocol fees for the rebalancing. (in USD)"},"requiredAllowances":{"description":"List of tokens for which the allowance has to be increased before executing the rebalancing. (List based on the wallet passed in the rebalancing request.)","type":"array","items":{"$ref":"#/components/schemas/AllowanceDto"}},"trades":{"description":"List of trades which will be executed to fulfill the rebalancing.","type":"array","items":{"$ref":"#/components/schemas/TradeDto"}},"txHandler":{"type":"string","description":"[Just if a batch trade is requested, otherwise use txHandler per trade] Address of the contract to send the txData to. It will be our <b>batch trade</b> contract if it is a rebalancing transaction. However, in some special cases, it may also be a different contract, for example, in the case of wrapping ETH into WETH."},"txData":{"type":"object","description":"[Just if a batch trade is requested, otherwise use txData per trade] Call data to execute the rebalancing. (Must be sent to the <code>txHandler</code> contract address.)"},"txValue":{"format":"int64","type":"integer","description":"Call value to execute the rebalancing. (Must be sent to the <code>txHandler</code> contract address.)"},"tokensWithoutPricePair":{"type":"string","description":"List of tokens for which no price pair could be found."},"executable":{"type":"boolean","description":"Is executable based on wallet permissions for smart contracts"},"expirationTimestamp":{"format":"date-time","type":"string","description":"If the rebalancing contains RFQ/OTC trades this is a hard deadline.If not this can be considered as soft deadline. A new rebalancing should be calculated since after some time market prices might have changed in a way that another composition of trades might be better."},"earliestRefreshQuotesTimestamp":{"format":"date-time","type":"string","description":"Earliest timestamp when quotes for this rebalancing can be refreshed"},"suggestedRefreshQuotesTimestamp":{"format":"date-time","type":"string"},"tenderlySimulation":{"description":"Tenderly simulation result.","allOf":[{"$ref":"#/components/schemas/TenderlySimulationDto"}]}},"required":["id","creationDate","baseValueInUsd","sellValueInUsd","estimatedValueLossInUsd","estimatedTargetValueInUsd","estimatedReceiveValueInUsd","minReceiveValueInUsd","estimatedImpact","maxImpact","estimatedGasUnits","suggestedGasPrice","estimatedGasFees","estimatedGasFeesInUsd","estimatedProtocolFeesInUsd","requiredAllowances","trades","txHandler","txData","txValue","tokensWithoutPricePair","executable","expirationTimestamp","earliestRefreshQuotesTimestamp","suggestedRefreshQuotesTimestamp","tenderlySimulation"]},"AllowanceDto":{"type":"object","properties":{"token":{"description":"Token address that needs allowance","allOf":[{"$ref":"#/components/schemas/SimpleTokenDto"}]},"allowanceTarget":{"type":"string","description":"Exchange proxy to set the allowance on"},"neededAllowance":{"format":"int64","type":"integer","description":"Allowance needed to execute rebalancing"},"currentAllowance":{"format":"int64","type":"integer","description":"Current allowance set on target"},"resetNeeded":{"type":"boolean","description":"Reset allowance to 0 before setting new one"}},"required":["token","allowanceTarget","neededAllowance","currentAllowance","resetNeeded"]},"SimpleTokenDto":{"type":"object","properties":{"address":{"type":"string","description":"Address of the token"},"name":{"type":"string","description":"Name of the token"},"symbol":{"type":"string","description":"Symbol of the token"},"imageUrl":{"type":"string","description":"Url of the token icon"},"decimals":{"type":"number","description":"Decimals of the token"},"sliderColor":{"type":"string","description":"Color based on the icon that can be used for elements in the frontend"},"chain":{"description":"Chain on which the token is deployed","allOf":[{"$ref":"#/components/schemas/ChainDto"}]},"tags":{"description":"Tags categorizing the token","type":"array","items":{"type":"string"}},"deflationary":{"type":"boolean","description":"Describes if this token is deflationary (e.g.: transfer fees)"}},"required":["address","name","symbol","imageUrl","decimals","sliderColor","chain","tags","deflationary"]},"ChainDto":{"type":"object","properties":{"name":{"type":"string","description":"Name of the chain"},"identifier":{"type":"string","description":"ID of the EVM base chain as hex value"},"enabled":{"type":"boolean","description":"Describes if rebalancings are enabled"},"batchTradeSupported":{"type":"boolean","description":"Describes if batch trade is supported"},"batchTradeAddress":{"type":"string","description":"Address of the deployed 31third-protocol BatchTrade contract"},"blockExplorerLink":{"type":"string","description":"Link of the most common block explorer"},"nativeTokenAddress":{"type":"string","description":"(Pseudo)-address of the chains native token"},"wrappedNativeTokenAddress":{"type":"string","description":"Address of the chains wrapped native token"},"tokenHelperAddress":{"type":"string","description":"Address of a helper contract capable of doing batch reads"},"portfolioEnabled":{"type":"boolean","description":"Describes if portfolio feature is enabled"}},"required":["name","identifier","enabled","batchTradeSupported","batchTradeAddress","blockExplorerLink","nativeTokenAddress","wrappedNativeTokenAddress","tokenHelperAddress","portfolioEnabled"]},"TradeDto":{"type":"object","properties":{"from":{"description":"Sell token.","allOf":[{"$ref":"#/components/schemas/SimpleTokenDto"}]},"to":{"description":"Receive token.","allOf":[{"$ref":"#/components/schemas/SimpleTokenDto"}]},"fromAmount":{"format":"int64","type":"integer","description":"Amount of the <code>from</code> token to sell. (In from token units)"},"toAmount":{"format":"int64","type":"integer","description":"Amount of the <code>to</code> token to receive. (In to token units; liquidity source fees are already included in this value)"},"minToReceiveBeforeFees":{"format":"int64","type":"integer","description":"Minimal amount of the <code>to</code> token to receive excluding fees. (In to token units; slippage and liquidity source fees are included in this value; protocol fees are excluded)"},"minToReceive":{"format":"int64","type":"integer","description":"Minimal amount of the <code>to</code> token to receive. (In to token units; slippage, liquidity source fees and protocol fees are included in this value)"},"fromValueInUsd":{"type":"number","description":"Value of the <code>from</code> token to sell. (in USD)"},"toValueInUsd":{"type":"number","description":"Value of the <code>to</code> token to receive. (in USD; liquidity source fees are already included in this value)"},"minToReceiveBeforeFeesInUsd":{"type":"number","description":"Minimal amount of the <code>to</code> token to receive excluding fees. (In USD; slippage and liquidity source fees are included in this value; protocol fees are excluded)"},"minToReceiveInUsd":{"type":"number","description":"Minimal value of the <code>to</code> token to receive. (in USD; slippage, liquidity source fees and protocol fees are included in this value)"},"estimatedPriceImpact":{"type":"number","description":"Estimated price impact in percent. [-1;1]. > 0 = value loss. < 0 = value gain","minimum":-1,"maximum":1},"maxSlippage":{"type":"number","description":"Maximum allowed slippage used for the calculation of this trade. (0.01 = 1%)","minimum":0,"default":0.005,"maximum":1},"price":{"type":"number","description":"Price of the <code>to</code> token in <code>from</code> token. Does not included slippage."},"guaranteedPrice":{"type":"number","description":"Guaranteed price of the <code>to</code> token in <code>from</code> token including slippage."},"previouslyRequiredTrades":{"description":"List of IDs of the trades that have to be executed before this trade.","type":"array","items":{"type":"string"}},"allowanceTarget":{"type":"string","description":"Allowance target to set the allowance to if <code>allowanceNeeded</code> is <code>true</code>"},"estimatedGasUnits":{"format":"int64","type":"integer","description":"Estimated gas units for this trade. (in WEI)"},"suggestedGasPrice":{"format":"int64","type":"integer","description":"Suggested gas price [LOW/MARKET/AGGRESSIVE] fetched from a block explorer (e.g. Etherscan). (in WEI)"},"estimatedGasFees":{"format":"int64","type":"integer","description":"Estimated gas fees for this trade [estimatedGasUnits * suggestedGasPrice]. (in WEI)"},"estimatedFees":{"format":"int64","type":"integer","deprecated":true,"description":"[USE estimatedGasFees INSTEAD] Estimated gas fees for this trade [estimatedGasUnits * suggestedGasPrice]. (in WEI)"},"expirationTimestamp":{"format":"date-time","type":"string","description":"Shows an approximate expiration estimation for this trade. When a trade is expired, <code>/rebalancing/refresh-expired-quotes</code> can be used to refresh the quote for this trade. Alternatively, a new rebalancing can be calculated."},"transactions":{"type":"array","items":{"type":"string"}},"fill":{"$ref":"#/components/schemas/FillDto"}},"required":["from","to","fromAmount","toAmount","minToReceiveBeforeFees","minToReceive","fromValueInUsd","toValueInUsd","minToReceiveBeforeFeesInUsd","minToReceiveInUsd","estimatedPriceImpact","maxSlippage","price","guaranteedPrice","previouslyRequiredTrades","allowanceTarget","estimatedGasUnits","suggestedGasPrice","estimatedGasFees","estimatedFees","expirationTimestamp","transactions","fill"]},"FillDto":{"type":"object","properties":{"liquiditySource":{"$ref":"#/components/schemas/SimpleLiquiditySourceDto"},"proportionInBps":{"type":"number"},"from":{"$ref":"#/components/schemas/SimpleTokenDto"},"to":{"$ref":"#/components/schemas/SimpleTokenDto"},"subFills":{"type":"array","items":{"type":"string"}}},"required":["liquiditySource","proportionInBps","from","to","subFills"]},"SimpleLiquiditySourceDto":{"type":"object","properties":{"identifier":{"type":"string"},"readableName":{"type":"string"},"iconUrl":{"type":"string"},"enabled":{"type":"boolean"}},"required":["identifier","readableName","iconUrl","enabled"]},"TenderlySimulationDto":{"type":"object","properties":{"status":{"type":"boolean","description":"Simulation status. True if tx simulation succeeded, false otherwise."},"errorMessage":{"type":"string","description":"Error message. Just present if <code>status</code> is <code>false</code>."},"blockNumber":{"type":"number","description":"Block number used for the simulation."},"gas":{"format":"int64","type":"integer","description":"Amount of gas provided for the simulation."},"gasUsed":{"format":"int64","type":"integer","description":"Amount of gas used for the simulation."}},"required":["status","errorMessage","blockNumber","gas","gasUsed"]}}}}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.31third.com/31third-api/basket-trade-m-n-swap/enzyme.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
