-
Notifications
You must be signed in to change notification settings - Fork 24
feat: how intents are formed #596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,322 @@ | ||||||||||||||||||||||
| --- | ||||||||||||||||||||||
| sidebar_position: 4 | ||||||||||||||||||||||
| --- | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # How Intents Are Formed | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| An _intent_ in CoW Protocol is a signed message that represents a user's wish to trade. It doesn't execute a trade directly — instead, it delegates execution to [solvers](../introduction/solvers) who find the optimal path. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| :::caution | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| This document explains the anatomy of intents and interaction with the API at a low level. | ||||||||||||||||||||||
| For practical use of the protocol, it is recommended to use high-level tools such as the **[CoW SDK](../../reference/sdks/cow-sdk)**. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ::: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Forming an intent follows three stages: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
| Intention → Quote → Intent | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
Comment on lines
+18
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MD040: All plain fenced code blocks are missing a language identifier. markdownlint-cli2 flags all of these. Add an appropriate language hint (e.g. ✏️ Proposed fixes (representative examples)-```
+```text
Intention → Quote → IntentVerify each finding against the current code and only fix it if needed. In |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## 1. Intention | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| An intention is the user's raw desire to trade. To obtain a quote, you send this intention to the `/quote` API endpoint: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
| POST https://api.cow.fi/mainnet/api/v1/quote | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The request body describes what the user wants. Basic fields of the request: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ```json | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| "kind": "sell", | ||||||||||||||||||||||
| "sellToken": "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14", | ||||||||||||||||||||||
| "buyToken": "0xbe72E441BF55620febc26715db68d3494213D8Cb", | ||||||||||||||||||||||
| "sellAmountBeforeFee": "1000000000000000000", | ||||||||||||||||||||||
| "from": "0xfb3c7eb936cAA12B5A884d612393969A557d4307", | ||||||||||||||||||||||
| "receiver": "0xfb3c7eb936cAA12B5A884d612393969A557d4307", | ||||||||||||||||||||||
| "validFor": 1800, | ||||||||||||||||||||||
| ... | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| | Field | Description | | ||||||||||||||||||||||
| |---|---| | ||||||||||||||||||||||
| | `kind` | `"sell"` or `"buy"` — whether you're fixing the sell or buy amount | | ||||||||||||||||||||||
| | `sellToken` | Token address you're selling | | ||||||||||||||||||||||
| | `buyToken` | Token address you're buying | | ||||||||||||||||||||||
| | `sellAmountBeforeFee` | How much you want to sell (for `sell` orders) | | ||||||||||||||||||||||
| | `from` | Address of the trader | | ||||||||||||||||||||||
| | `receiver` | Address that receives the bought tokens (often same as `from`) | | ||||||||||||||||||||||
| | `validFor` | Order validity period in seconds | | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| :::note | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| More details see in [Order Book API](../../reference/apis/orderbook.mdx) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ::: | ||||||||||||||||||||||
|
Comment on lines
+55
to
+59
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Grammar: "More details see in" ✏️ Proposed fix📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## 2. Quote | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The `/quote` response provides the price information needed to build the order, including fee breakdowns. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### Sell order response | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| <img alt="Quote for Sell Order" src="/img/concepts/intents/sell-order-quote.png" width="540"/> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| --- | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ```json | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| "protocolFeeBps": "2", | ||||||||||||||||||||||
| "quote": { | ||||||||||||||||||||||
| "buyAmount": "191179999", | ||||||||||||||||||||||
| "feeAmount": "62483346430736", | ||||||||||||||||||||||
| "sellAmount": "99937516653569264", | ||||||||||||||||||||||
| "kind": "sell" | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| ... | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| | Field | Description | | ||||||||||||||||||||||
| |---|---| | ||||||||||||||||||||||
| | `protocolFeeBps` | Protocol fee in basis points | | ||||||||||||||||||||||
| | `quote.sellAmount` | Sell amount **after** network costs have been deducted | | ||||||||||||||||||||||
| | `quote.feeAmount` | Network costs, in **sell token** units | | ||||||||||||||||||||||
| | `quote.buyAmount` | Buy amount **after** network costs and protocol fee have been deducted | | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### Buy order response | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| <img alt="Quote for Buy Order" src="/img/concepts/intents/buy-order-quote.png" width="540"/> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| --- | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ```json | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| "protocolFeeBps": "2", | ||||||||||||||||||||||
| "quote": { | ||||||||||||||||||||||
| "buyAmount": "200000000", | ||||||||||||||||||||||
| "feeAmount": "42560776189182", | ||||||||||||||||||||||
| "sellAmount": "104486220751250279", | ||||||||||||||||||||||
| "kind": "buy" | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| ... | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| For buy orders, `sellAmount` is **after** the protocol fee, and the `feeAmount` (network costs) is **not yet included** in the sell amount — it must be added separately. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## 3. Amount Stages | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The quote response and order construction use a shared vocabulary of amount stages — each representing the token amount at a specific point in the fee pipeline. Understanding these terms is essential for interpreting quote values and building orders correctly. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| | Term | Description | | ||||||||||||||||||||||
| |---|---| | ||||||||||||||||||||||
| | **`beforeAllFees`** (= `spotPrice`) | The raw exchange rate with no fees applied. This is the theoretical "perfect world" price. It serves as the reference point for calculating partner fees and slippage. | | ||||||||||||||||||||||
| | **`afterProtocolFees`** | Amount after CoW Protocol's own fee (`protocolFeeBps`) has been applied. | | ||||||||||||||||||||||
| | **`afterNetworkCosts`** | Amount after gas costs (network costs) have been applied. Network costs are always denominated in the **sell token**, but may be converted to buy token units when applied to the buy side. | | ||||||||||||||||||||||
| | **`afterPartnerFees`** | Amount after the integrator/partner fee has been deducted. | | ||||||||||||||||||||||
| | **`afterSlippage`** | The final amount after the user's slippage tolerance has been applied. **This is the value signed into the order** — it is the minimum the user will receive (sell orders) or the maximum they will pay (buy orders). | | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### Flow for sell orders | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|  | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| [//]: # (TODO: add a link to SDK) | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unresolved TODO comments in published documentation. Both lines contain Also applies to: 170-170 🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The `/quote` response maps directly to `afterNetworkCosts`. `beforeAllFees` is reconstructed from it for partner fee calculations: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ```ts | ||||||||||||||||||||||
| // /quote response maps to afterNetworkCosts | ||||||||||||||||||||||
| const afterNetworkCosts = { | ||||||||||||||||||||||
| sellAmount: quote.sellAmount, | ||||||||||||||||||||||
| buyAmount: quote.buyAmount, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // reconstruct beforeAllFees (spot price) — used as the base for partner fee calculation | ||||||||||||||||||||||
| const networkCostAmountInBuyCurrency = (quote.buyAmount * quote.feeAmount) / quote.sellAmount | ||||||||||||||||||||||
| const beforeAllFees = { | ||||||||||||||||||||||
| sellAmount: quote.sellAmount + quote.feeAmount, | ||||||||||||||||||||||
| buyAmount: quote.buyAmount + networkCostAmountInBuyCurrency + protocolFeeAmount, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // partner fee is deducted from buy amount, relative to spot price | ||||||||||||||||||||||
| const afterPartnerFees = { | ||||||||||||||||||||||
| sellAmount: afterNetworkCosts.sellAmount, | ||||||||||||||||||||||
| buyAmount: afterNetworkCosts.buyAmount - partnerFeeAmount, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| // partnerFeeAmount = beforeAllFees.buyAmount * partnerFeeBps / 10000 | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // slippage reduces buy amount (user accepts receiving less) | ||||||||||||||||||||||
| const afterSlippage = { | ||||||||||||||||||||||
| sellAmount: afterPartnerFees.sellAmount, | ||||||||||||||||||||||
| buyAmount: afterPartnerFees.buyAmount - slippageAmount, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| // slippageAmount = afterPartnerFees.buyAmount * slippageBps / 10000 | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // sell is set to spot price — settlement contract deducts network costs itself | ||||||||||||||||||||||
| const amountsToSign = { | ||||||||||||||||||||||
| sellAmount: beforeAllFees.sellAmount, // = quote.sellAmount + quote.feeAmount | ||||||||||||||||||||||
| buyAmount: afterSlippage.buyAmount, // minimum to receive | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### Flow for buy orders | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| [//]: # (TODO: add a link to SDK) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|  | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The `/quote` sell amount maps to `afterProtocolFees`. The buy amount is fixed and maps to `beforeAllFees`: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ```ts | ||||||||||||||||||||||
| // /quote response: sell maps to afterProtocolFees, buy is fixed (= beforeAllFees) | ||||||||||||||||||||||
| const afterProtocolFees = { | ||||||||||||||||||||||
| sellAmount: quote.sellAmount, | ||||||||||||||||||||||
| buyAmount: quote.buyAmount, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // reconstruct beforeAllFees (spot price) — used as the base for partner fee calculation | ||||||||||||||||||||||
| const beforeAllFees = { | ||||||||||||||||||||||
| sellAmount: quote.sellAmount - protocolFeeAmount, | ||||||||||||||||||||||
| buyAmount: quote.buyAmount, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // add network costs to sell amount | ||||||||||||||||||||||
| const afterNetworkCosts = { | ||||||||||||||||||||||
| sellAmount: quote.sellAmount + quote.feeAmount, | ||||||||||||||||||||||
| buyAmount: quote.buyAmount, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // partner fee is added to sell amount, relative to spot price | ||||||||||||||||||||||
| const afterPartnerFees = { | ||||||||||||||||||||||
| sellAmount: afterNetworkCosts.sellAmount + partnerFeeAmount, | ||||||||||||||||||||||
| buyAmount: afterNetworkCosts.buyAmount, | ||||||||||||||||||||||
| // partnerFeeAmount = beforeAllFees.sellAmount * partnerFeeBps / 10000 | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // slippage increases sell amount (user accepts paying more) | ||||||||||||||||||||||
| const afterSlippage = { | ||||||||||||||||||||||
| sellAmount: afterPartnerFees.sellAmount + slippageAmount, | ||||||||||||||||||||||
| buyAmount: afterPartnerFees.buyAmount, | ||||||||||||||||||||||
| // slippageAmount = afterPartnerFees.sellAmount * slippageBps / 10000 | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // buy is fixed (exact amount to receive), sell includes all fees and slippage | ||||||||||||||||||||||
| const amountsToSign = { | ||||||||||||||||||||||
| sellAmount: afterSlippage.sellAmount, // maximum to pay | ||||||||||||||||||||||
| buyAmount: beforeAllFees.buyAmount, // = quote.buyAmount | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## 4. Fees & Slippage | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Several layers of fees transform the raw spot price into the final amounts signed in the order. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### Fee types | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| | Fee | Description | Token | | ||||||||||||||||||||||
| |---|---|---| | ||||||||||||||||||||||
| | **Network costs** | Gas fees for on-chain execution, estimated by the protocol | Sell token | | ||||||||||||||||||||||
| | **Protocol fee** | CoW Protocol's fee, expressed in basis points (`protocolFeeBps`) | Buy token (sell orders) / Sell token (buy orders) | | ||||||||||||||||||||||
| | **Partner fee** | Optional fee added by integrators (e.g. widget providers) | Buy token (sell orders) / Sell token (buy orders) | | ||||||||||||||||||||||
| | **Slippage** | Tolerance buffer to account for price movements | Buy token (sell orders) / Sell token (buy orders) | | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## Spot Price (beforeAllFees) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The spot price is the exchange rate before any fees are applied. It serves as the reference for partner fee and slippage calculations. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### Sell order | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
| beforeAllFees.sellAmount = quote.sellAmount + quote.feeAmount | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Network Costs (buy token) = (quote.buyAmount × quote.feeAmount) / quote.sellAmount | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| beforeAllFees.buyAmount = quote.buyAmount + protocolFeeAmount + Network Costs (buy token) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### Buy order | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
| beforeAllFees.sellAmount = quote.sellAmount - protocolFeeAmount | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| beforeAllFees.buyAmount = quote.buyAmount\ | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
Comment on lines
+247
to
+251
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stray trailing backslash on ✏️ Proposed fix📝 Committable suggestion
Suggested change
🧰 Tools🪛 markdownlint-cli2 (0.21.0)[warning] 243-243: Fenced code blocks should have a language specified (MD040, fenced-code-language) 🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## Protocol Fee | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The protocol fee is expressed as basis points (`protocolFeeBps`) in the quote response. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### Sell orders (buy token units) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| For sell orders, `quote.buyAmount` is already **after** the protocol fee has been deducted: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
| protocolFeeAmount = quote.buyAmount × protocolFeeBps / (1 − protocolFeeBps) | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### Buy orders (sell token units) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| For buy orders, the protocol fee is applied to the sum of sell amount and network costs: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
| protocolFeeAmount = (quote.sellAmount + quote.feeAmount) × protocolFeeBps / (1 + protocolFeeBps) | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
Comment on lines
+261
to
+271
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Protocol fee formulas are mathematically wrong —
🐛 Proposed fix-protocolFeeAmount = quote.buyAmount × protocolFeeBps / (1 − protocolFeeBps)
+protocolFeeAmount = quote.buyAmount × (protocolFeeBps / 10000) / (1 − protocolFeeBps / 10000)-protocolFeeAmount = (quote.sellAmount + quote.feeAmount) × protocolFeeBps / (1 + protocolFeeBps)
+protocolFeeAmount = (quote.sellAmount + quote.feeAmount) × (protocolFeeBps / 10000) / (1 + protocolFeeBps / 10000)🧰 Tools🪛 markdownlint-cli2 (0.21.0)[warning] 257-257: Fenced code blocks should have a language specified (MD040, fenced-code-language) [warning] 265-265: Fenced code blocks should have a language specified (MD040, fenced-code-language) 🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## Partner Fee | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The partner (integrator) fee is calculated as a percentage of the **spot price** (`beforeAllFees`), not the post-fee amounts. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### Sell orders (buy token units) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
| partnerFeeAmount = beforeAllFees × partnerFeePercent / 100 | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### Buy orders (sell token units) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The same formula applies, but the result is in sell token units. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
Comment on lines
+279
to
+286
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Partner fee formulas reference
✏️ Proposed fix ### Sell orders (buy token units)
-partnerFeeAmount = beforeAllFees × partnerFeePercent / 100 🤖 Prompt for AI Agents |
||||||||||||||||||||||
| ## Slippage | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Slippage tolerance uses the same calculation as the partner fee, but it is applied to the **`afterPartnerFees`** amount rather than the spot price: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
| slippageAmount = afterPartnerFees × slippagePercent / 100 | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
Comment on lines
+279
to
+293
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent units between formula sections and inline code — bps vs percent. The Either align the formula notation to use bps consistently, or add a brief inline note making the equivalence explicit (e.g., 🧰 Tools🪛 markdownlint-cli2 (0.21.0)[warning] 275-275: Fenced code blocks should have a language specified (MD040, fenced-code-language) [warning] 287-287: Fenced code blocks should have a language specified (MD040, fenced-code-language) 🤖 Prompt for AI Agents
Comment on lines
+287
to
+293
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Slippage formula uses Same ambiguity as the partner fee formula: ✏️ Proposed fix ### Sell orders
-slippageAmount = afterPartnerFees × slippagePercent / 100
+slippageAmount = afterPartnerFees.buyAmount × slippagePercent / 100
### Buy orders
+slippageAmount = afterPartnerFees.sellAmount × slippagePercent / 100🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## Forming the Final Order | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The signed order combines the quote API response with UI/integrator settings: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| | Source | Fields | | ||||||||||||||||||||||
| |---|---| | ||||||||||||||||||||||
| | `/quote` API response | `sellAmount`, `buyAmount`, `feeAmount`, `protocolFeeBps` | | ||||||||||||||||||||||
| | UI / integrator settings | `partnerFee`, `slippage` | | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The resulting order contains the **`afterSlippage`** buy amount (for sell orders) or sell amount (for buy orders), which the protocol guarantees as the minimum the user will receive (or maximum they'll pay). Fixed amount is the spot price amount. | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unclear closing sentence in "Forming the Final Order" intro. "Fixed amount is the spot price amount." is incomplete — it doesn't identify which amount is fixed, for which order type, or why. Suggest replacing with a clearer summary: ✏️ Proposed fix-The resulting order contains the **`afterSlippage`** buy amount (for sell orders) or sell amount (for buy orders), which the protocol guarantees as the minimum the user will receive (or maximum they'll pay). Fixed amount is the spot price amount.
+The resulting order contains the **`afterSlippage`** buy amount (for sell orders) or sell amount (for buy orders), which the protocol guarantees as the minimum the user will receive (or maximum they'll pay). The complementary amount (sell for sell-orders, buy for buy-orders) is set to the **spot price** (`beforeAllFees`), allowing solvers to capture any surplus above the guaranteed amount.🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### Sell order | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ```typescript | ||||||||||||||||||||||
| const orderToSign = { | ||||||||||||||||||||||
| sellAmount: beforeAllFees.sellAmount, | ||||||||||||||||||||||
| buyAmount: afterSlippage.buyAmount | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### Buy order | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ```typescript | ||||||||||||||||||||||
| const orderToSign = { | ||||||||||||||||||||||
| sellAmount: afterSlippage.sellAmount, | ||||||||||||||||||||||
| buyAmount: beforeAllFees.buyAmount | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stage count inconsistency between intro and section headers.
Line 16 states "three stages" and the diagram shows
Intention → Quote → Intent, but the document has four numbered sections (1. Intention,2. Quote,3. Amount Stages,4. Fees & Slippage). Either update the intro to reflect four stages, or re-label/un-number sections 3 and 4 as subsections of intent formation so they don't look like top-level stages.🧰 Tools
🪛 markdownlint-cli2 (0.21.0)
[warning] 18-18: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for AI Agents