# Calculating Quotes

Calculating quotes for swaps and other operations requires knowledge of the current pool state including fee parameters, reserves, issued protocol tokens, etc. This information can be retrieved from the local state of the Tinyman app in the pool account. It is important to use fresh state data when calculating quotes as pool ratios and prices can change quickly.

## Swap

### **Fixed Input**

See [Formula IV.A](https://docs.tinyman.org/v2-integration/pages/RArypJMatkCdksZvFhuW#a.-fixed-input)

Fixed Input Swap from asset 1 to asset 2

total\_fee = (input\_amount \* state\["total\_fee\_share"]) / 10000\
swap\_amount = input\_amount - total\_fee\
k = state\["asset\_1\_reserves"] \* state\["asset\_2\_reserves"]\
swap\_output = state\["asset\_2\_reserves"] - (floor(k / (state\["asset\_1\_reserves"] + swap\_amount)) + 1)

Allowing for a slippage of 1%, min\_output\_amount should be set as swap\_output \* 0.99

### **Fixed Output**

See[ Formula IV.B](https://docs.tinyman.org/v2-integration/pages/RArypJMatkCdksZvFhuW#b.-fixed-output)

Fixed Output Swap from asset 1 to asset 2

k = state\["asset\_1\_reserves"] \* state\["asset\_2\_reserves"]\
swap\_amount = (floor(k / (state\["asset\_2\_reserves"] - output\_amount)) + 1) - state\["asset\_1\_reserves"]\
input\_amount = floor((swap\_amount \* 10000) / (10000 - state\["total\_fee\_share"]))

Allowing for a slippage of 1%, input\_amount should be set as input\_amount \* 1.01


---

# 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.tinyman.org/v2-integration/calculating-quotes.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.
