# What is Carbon DeFi?

An orderbook-style DEX allowing users to perform novel trading strategies with all standard ERC20 tokens\*[^1] using a variety of order types:

* [**Limit Order**](/strategy-types/limit-order) - A single disposable buy or sell order at a specific price
* [**Range Order** ](/strategy-types/range-order)- A single disposable buy or sell order within a custom price range
* [**Recurring Orders**](/strategy-types/recurring-orders) - buy and sell orders (limit or range) that are linked together, and perform similar to grid trading or a DEX trading bot. Newly acquired funds automatically rotate between them, creating an endless trading cycle without need for manual intervention
* [Concentrated Liquidity](/strategy-types/concentrated-liquidity), previously referred to as [**Overlapping Liquidity**](/strategy-types/concentrated-liquidity) - Enables users to manage concentrated liquidity positions within specific price ranges easily and efficiently onchain. Drawing from Automated Market Maker (AMM) models, this tool allows for direct customization of your spread (aka the “fee” level).

<figure><img src="/files/dYPLqUhL2qutuU7a2cS8" alt=""><figcaption></figcaption></figure>

By design, Carbon DeFi's limit, range, and recurring orders are all irreversible on execution, easily adjustable, resistant to MEV sandwich attacks, fully onchain, non-custodial and can be deployed with any standard ERC20 token. These capabilities give users an unprecedented level of control and automation to perform novel trading strategies.

Explainer Video 👇

{% embed url="<https://www.youtube.com/watch?v=0kKEJ4JCk6U>" %}

Resources:

* ​[Carbon DeFi Website](https://www.carbondefi.xyz/)
* [Strategy Creation Guide](/getting-started/creating-a-strategy)
* ​[Smart Contract Code](https://github.com/bancorprotocol/carbon-contracts)
* [Dune Analytics​](https://dune.com/bancor/carbon-by-bancor)
* [Technical Documentation​](https://docs.carbondefi.xyz/contracts-and-functions/contracts)
* ​[Whitepaper](http://carbondefi.xyz/whitepaper)​
* ​[Litepaper](http://carbondefi.xyz/litepaper)

[^1]: rebase tokens and fee-on-transfer token are not supported <br>

    What is a rebase token?

    <https://www.coindesk.com/learn/what-is-a-rebaseelastic-token/>


# What Makes Carbon DeFi Unique?

Carbon DeFi distinguishes itself from existing automated market makers (AMMs) in several key ways:&#x20;

1. Adjustable Fee: Users who provide liquidity ("makers") can set a specific buy range and a specific sell range for their tokens, which establishes a custom fee/spread, instead of all makers having to adopt the fee that is prescribed by the AMM.
2. Rotating Liquidity: Liquidity is automatically moved between the maker's selected buy/sell ranges as orders are executed.
3. Irreversible Orders: User liquidity trades in one direction, irreversibly.
4. MEV Resistance: Spot trading is protected from MEV sandwich attacks.

<figure><img src="https://miro.medium.com/v2/resize:fit:1400/1*SzNF-OWBXG5SUSTS_4ZOgw.png" alt="" height="525" width="700"><figcaption></figcaption></figure>

### Adjustable Fee

Users who create strategies in Carbon DeFi ("makers") are similar to liquidity providers in existing AMMs in that their activities supply liquidity for trading, and they collect fees from other users ("takers") who perform spot trades using their liquidity.&#x20;

However, Carbon DeFi is unique in that each individual maker can customize the fee they collect from trades - i.e., the difference between their selected buy and sell ranges. While legacy AMMs force their liquidity providers to adopt the fee of the AMM they're providing liquidity to, Carbon DeFi lets LPs set their own personalized fee (or spread) by selecting the specific price(s) where they'd like to buy and sell their tokens.

### Rotating Liquidity

When a user provides liquidity in existing on-chain liquidity protocols/AMMs, their position buys and sells tokens using a single pricing curve ("bonding curve").

In Carbon DeFi, each user position consists of two bonding curves (or "orders") - one for buying and one for selling. When a user deposits a token pair, each token in the pair has one custom curve based on settings decided by the user. Once your position buys or sells at your desired price, your liquidity is automatically rotated to its paired curve, and vice versa.&#x20;

In the case of a single-use limit or range order on Carbon DeFi, as the order is executed, liquidity is taken "off-curve" and shifted to an inactive paired order, where it sits idle until the maker withdraws their position.

In the case of a recurring strategy, buy and sell orders trade in perpetuity, and liquidity continuously shifts between the paired orders as trades are executed, until the user chooses to stop the strategy. Such a strategy offers to buy in one price range and sell in a higher range akin to a "Grid Trading" or "Scalping" strategy.

### Unidirectional, Irreversible Orders

In existing concentrated liquidity protocols like Uniswap V3, executed orders may be reversed when markets retrace. This is due the bidirectional nature of AMM liquidity: Once a buy order for one asset is traded against, a sell order for the other asset is placed at the same price. To avoid order reversal, users must manually monitor and withdraw their liquidity upon execution (or rely on external tooling to do so).

In contrast, limit/range orders in Carbon DeFi flow in a single direction and are therefore irreversible on execution. This removes the need for users to constantly monitor their orders and manually withdraw in time, or rely on a third-party to do so. [Read more about Carbon DeFi limit orders](broken://pages/0tadOqbNBRCo8oz7slWK)[.](https://medium.com/carbondefi/true-dex-limit-orders-carbon-vs-existing-solutions-58cd955098fd)

### MEV Protection

Due to the irreversibility of Carbon DeFi orders, spot trades that execute against Carbon DeFi strategies are protected from MEV sandwich attacks. [Read more about Carbon DeFi and MEV](https://medium.com/carbondefi/carbon-the-mev-sandwich-is-toast-2ec7800dde68).


# Participants

There are two key market participants in Carbon DeFi:

1. “Makers” submit automated strategies composed of one or two onchain limit or range orders.
2. “Takers” perform “spot” trades against live strategies directly, via DEX aggregators, or as arbitrageurs. Spot trading requests are handled by way of a decentralized [SDK](broken://pages/3p7P9Hdjypektrb5MncV) or using any custom software capable of processing the on-chain data.

Makers are similar to liquidity providers in legacy automated market makers (AMMs) in that their activities support the liquidity of the system in an on-chain, permissionless manner. However, they are notably different in that each maker can customize their own personalized spread or "fee tier" between their buy and sell ranges. This is in contrast to existing AMMs which force liquidity providers to adopt the fee of the AMM they're providing liquidity to.


# Creating a Strategy

This guide walks you through creating a strategy on [app.carbondefi.xyz](<https://app.carbondefi.xyz/ >)

We'll create a recurring strategy with ETH and USDC that buys ETH between $2000 and $2100 and sells ETH between $2300 and 2400. We will fund the strategy with USDC tokens only.

{% embed url="<https://www.youtube.com/watch?v=i7KN903eUWQ>" %}
A step-by-step video guide to creating a Carbon strategy.
{% endembed %}

## 1. Select a token pair

<figure><img src="/files/V7jDJkVM7VnuNWHSUUxf" alt=""><figcaption></figcaption></figure>

Any pair of standard ERC20 tokens is valid. The “Buy or Sell” token (or “Base token”) is the token we would like to buy low and sell high, in this case ETH. The “With token” (or “Quote token”) is the token we would like to denominate rates in, in this case USDC.

## 2. Select the strategy type

<figure><img src="/files/gfMIYmGv0h8vMuKiKcJy" alt=""><figcaption></figcaption></figure>

Choose between few different options:

* Limit Order&#x20;
* Range Order
* Recurring Order
* Concentrated Liquidity, previously referred to as 'Overlapping Liquidity'

In this case, we select a recurring order with two range orders.

## 3. Enter a Buy Range and Buy Budget

<figure><img src="/files/BDstvbqp83Y9K9cgqw66" alt=""><figcaption></figcaption></figure>

In this example, there will be a supporting [ETHUSD](https://www.tradingview.com/symbols/ETHUSDC/) price chart powered by TradingView. You can utilize this chart to select your ranges using available data points such as trading volume, price action, moving average indicator and more.&#x20;

The Buy Range is set to $2000-$2100. Meaning the strategy will start buying ETH at $2100 (“Max”) and stop buying ETH at $2000 (“Min”).

We fund the Buy Budget with 1000 USDC. Our USDC will be converted into ETH whenever the ETH market price enters the Buy Range.

## 4. Enter a Sell Range and Sell Budget

<figure><img src="/files/Q7empSr1eUTaIsKwLoMM" alt=""><figcaption></figcaption></figure>

The Sell Range is set to $2300-$2400. Meaning the strategy will start selling ETH at $2300 (“Min”) and stop selling ETH at $2400 (“Max”).&#x20;

We fund the Sell Budget with 0 ETH.

## 5. Create Strategy

We are now ready to submit the transaction that creates our strategy. First, we may need to approve the Carbon contract to spend tokens on our behalf.

<figure><img src="/files/VOy9ubmmaFkgw9xanQC2" alt=""><figcaption></figcaption></figure>

Once the approve transaction has been confirmed, click “Create Strategy” to trigger the transaction in your wallet.

<figure><img src="/files/waKbqH9JR8uXg2oxas5x" alt=""><figcaption></figcaption></figure>

## 6. Manage Strategy

<figure><img src="/files/V2xPrrsHV300PxGQKg7f" alt=""><figcaption></figcaption></figure>

That's it! The strategy is now live and will appear in the Strategies page. Click “Manage” to interact with the strategy, including Deleting the strategy, Editing price ranges, Depositing or Withdrawing funds, or Pausing the strategy.

For more info on Carbon’s recurring strategies, see this [blog post](https://medium.com/carbondefi/adventures-in-programmable-dex-trading-carbon-recurring-strategies-6be01b534ae0).

## Questions?

* [Carbon DeFi Telegram](https://t.me/CarbonDeFixyz)
* [Carbon DeFi Discord](https://discord.gg/bancor)
* [Technical Documentation](https://docs.carbondefi.xyz/carbon/introducing-carbon)


# Limit Order

A one-time buy order or sell order that executes at a specific price. Use limit orders to set your precise entry and exit points. e.g., Buy ETH at $1600&#x20;

<figure><img src="/files/JybvfxiCsk2HrfLYnoAa" alt=""><figcaption></figcaption></figure>

### Benefits of Carbon DeFi

* **Irreversible**\
  Similar to a limit order on a centralized exchange, an order will not be undone should the market retrace.
* **Adjustable**\
  Easily edit without withdrawing funds. Adjust orders onchain, saving time and gas.
* **Zero Slippage**\
  The price you set is what you'll receive.
* **MEV - Sandwich Attack Resistant**

  Due to it's irreversible nature.

<figure><img src="/files/tEbQh4SZ3einaEw0BilS" alt=""><figcaption></figcaption></figure>

Existing DeFi projects have tried to incorporate limit orders into AMM models, but these efforts have generally fallen short of replicating true limit order system functionality and rely on external third parties, such as keepers and/or oracles.&#x20;

Carbon DeFi addresses this gap with its purpose-built product, designed specifically for genuine maker orders without relying on third parties. Carbon DeFi ensures onchain transparency in liquidity and settlement processes, marking a significant advancement in the capabilities of DeFi.

***

Further Reading: [True DEX Limit Orders: Carbon DeFi vs. Existing Solutions](https://medium.com/carbondefi/true-dex-limit-orders-carbon-vs-existing-solutions-58cd955098fd)


# Range Order

Range orders allow you to easily scale in or out of a position, automating the process of averaging your entry or exit price. Set a single order to buy or sell a token within a specific price range, such as buying ETH from $1900–1800 or selling ETH from $2000-2100.&#x20;

<figure><img src="/files/qFW1TdtFMeVMY4yPvlBo" alt=""><figcaption></figcaption></figure>

### Benefits of Carbon DeFi

* **Irreversible**\
  Once orders within your range are filled, they will not be undone should the market retrace.
* **Partial Fills**\
  Range orders can be partially filled and remain irreversible.&#x20;
* **No Trading or Gas Fees on Filled Orders**

  Makers pay no gas when a trade is executed, and there are currently no maker fees on Carbon DeFi.
* **Adjustable**\
  Easily edit without withdrawing funds. Adjust orders onchain, saving time and gas.
* **Zero Slippage**\
  The price you set is what you'll receive.
* **MEV - Sandwich Attack Resistant**

  Due to it's irreversible nature.

Carbon DeFi's range orders not only simplify the scaling in and out processes but also add a layer of security and predictability to trading in the DeFi space.<br>

***

More on Scaling In and Scaling Out using Carbon DeFi’s range orders: [Crypto Trading 101: Scaling In and Out](https://medium.com/carbondefi/crypto-trading-101-scaling-in-and-out-16f2ef27373d)


# Recurring Orders

Enable linked buy and sell orders to trade perpetually. An innovative approach to automated trading strategies, akin to grid trading or using a DEX trading bot, recurring orders revolve around repeating "buy low, sell high" trades.

For instance, you could set a recurring order to buy TKN from $1,900 to $1,800 and sell it from $2,100 to $2,200, with the ability to initially fund one or both orders.&#x20;

Once tokens are acquired in a buy order for example, the liquidity automatically rotates and funds the linked sell order, creating a self-perpetuating trading loop. This cycle operates continuously without needing manual intervention, allowing users to compound profits through a custom, self-sustaining trading strategy.&#x20;

<figure><img src="/files/498BBaIAJ5YW6AQKsM3d" alt=""><figcaption></figcaption></figure>

### Benefits

* **Rotating Liquidity**

  Tokens acquired in a buy order instantaneously fund the linked sell order and vice versa. Compound profits with a custom trading strategy designed to run continuously.
* **Provide just one or both tokens**\
  With rotating liquidity, users are able to create orders with tokens they don't yet have, giving them the option to add liquidity to just one of the linked buy and sell orders.&#x20;
* **Adjustable**\
  Easily edit without withdrawing funds. Adjust orders onchain, saving time and gas.
* **No Trading or Gas Fees on Filled Orders**

  Makers pay no gas when a trade is executed, and there are currently no maker fees on Carbon DeFi.
* **Irreversible**\
  Once orders are filled, they will not be undone should the market retrace.
* **Partial Fills**\
  Orders can be partially filled and remain irreversible.&#x20;
* **Zero Slippage**\
  The price you set is what you'll receive.
* **MEV - Sandwich Attack Resistant**

  Due to it's irreversible nature.

<figure><img src="/files/TjONmUwQw8NA0feZS8am" alt=""><figcaption></figcaption></figure>

Further Reading: [Automated Recurring Limit Orders Explained](https://medium.com/carbondefi/automated-recurring-limit-orders-explained-8a137b8bb206)<br>


# Concentrated Liquidity

A Concentrated Liquidity strategy, previously referred to as 'Overlapping Liquidity' is a concentrated position where you buy and sell in a custom price range, used to create a bid-ask spread that moves as the market does.

### Concentrated Liquidity

Concentrated Liquidity strategies utilize the powerful Carbon DeFi engine and allow users to create a concentrated product sum liquidity position.&#x20;

This results in a strategy that mimics AMM trading solutions where there is always buy and sell prices that move on the same bonding curve together in a symmetrical way.

Users who choose to utilize this ability can control the fee tier, which provides more control over the spread applied between the offered buy and sell prices.

#### Choosing Price Range

Prices can be set by dragging the chart indicators in either direction or by inputting the exact value in the relevant input field below the chart area.

<figure><img src="/files/c6D16KB63Qc2jqASH20K" alt=""><figcaption></figcaption></figure>

The strategy can be set at price range above, below, or around current market price.

* "Above market price" will set the strategy to initiate with Sell High budget and be ready to sell the available budget as soon as market price goes up into the range.&#x20;
* "Below market price" will set the strategy to initiate with Buy Low budget and be ready to buy using the available budget as soon as market price goes down into the range.
* "Around market price" will set the strategy to initiate with both Buy Low and Sell High budgets ready to be utilized as soon as market price moves in either direction.

When setting prices, the system shows how close the minimum and maximum prices are to the current market price. It does this by indicating the percentage change needed to align the current price with the set price limits, aiding in decision-making.

<figure><img src="/files/dNmvK89v1HaYJvRcNG9p" alt=""><figcaption></figcaption></figure>

#### Indicate Fee Tier, previously referred to as 'Spread'

Fee tier value will define the gap (or space) between the prices of the Buy and Sell orders. This in fact serves as a fee that is defined by the strategy owner.

```
Calculating the Spread into price units:
Spread: 1%
Min Buy Price: 1500
Max Sell Price: 2000
This will result in 2 overlapping orders in the strategy
SellHigh:
- SellHigh.MinPrice = 1500*(101%) = 1515
- SellHigh.MaxPrice = 2000
BuyLow:
- BuyLow.MinPrice = 1500
- BuyLow.MaxPrice = 2000/(101%) = 1980.1980
```

### Concentrated Budget Dynamics

The special correlating dynamics of the concentrated liquidity strategy forces the budgets to be adjusted in relation to one another. Because it is designed to maintain an identical fee, or spread, across all price points and move together on a single bonding curve, when indicating sell budget, the buy budget must be calculated using the strategy details.

However, if the indicated strategy price range is set outside (above or below) current market price, the strategy would only require 1 budget to be deposited for two reasons:

* Prevent from having an immediate arb opportunity that can take the available budget at a discount
* Maintain the strategy dynamics where the buy and sell orders correlate and when one side is taken, the other gets filled


# Editing Concentrated Liquidity Strategy

Carbon DeFi's adjustable strategy design allows users to perform various edits on existing strategies. This unique ability supports quicker and cheaper edits that allows users to be in control of their position and have the flexibility to adjust as the market moves.

### Depositing into a concentrated liquidity strategy

When depositing additional funds into an existing strategy, the budget requirements will be calculated using the strategy prices, spread, and current market price. This is done to maintain the unique overlapping symmetry of the orders and maintain the desired spread between them.

{% hint style="info" %}
Price range and liquidity spread remain unchanged when adding more funds.
{% endhint %}

### Withdrawing from a concentrated liquidity strategy

When withdrawing funds from an existing strategy, the budget correlation must be maintained for both orders. The result might be a case in which withdrawing one budget will also force partial removal of the 2nd budget that is allocated to the strategy. This is done to avoid creating an arbitrage opportunity that will unbalance the dynamics of the strategy.

{% hint style="info" %}
Price range and liquidity spread remain unchanged when withdrawing funds.
{% endhint %}

### Editing prices and/or spread of a concentrated liquidity strategy

Editing prices and spread of an existing strategy might result in budget updates as the strategy should maintain a unique balance of symmetry. When performing a price edit, a user will be informed of the required changes, and if budget changes are required to fit the new user settings.&#x20;


# Order Dynamics

## Marginal Price

Marginal price indicates the order "best" price at the moment, which is also the starting price for any trader to interact with.

<figure><img src="/files/hQpaX3uRoPAf42PlOGZR" alt=""><figcaption><p>Carbon DeFi - Marginal Price</p></figcaption></figure>

### Example:

![](/files/pj7vpxVtue532zf16UdR)![](/files/QmgIwOm1ZWxdBrqBSJyL)

1. User creates a strategy between ETH/USDC:
   1. Sell 100 ETH between 1650-1700 USDC
   2. Buy ETH with 10,000 USDC budget between 1590-1640 USDC
2. On creation, the "Marginal price" would be:
   1. Sell marginal price is **1650 USDC** as this is the starting price for traders
   2. Buy marginal price is **1640 USDC** as this is the starting price for traders
3. A trader interacted with the Sell order and took 20 ETH from the order
   1. Sell marginal price will change from 1650 USDC to **1659 USDC** (as it is slowly moving to 1700 USDC)
   2. A trader took additional 30 ETH from the order
   3. Sell marginal price will change from 1659 USDC to **1674 USDC**
4. A trader now interacts with the Buy order and gave it 10 ETH (in return for USDC)
   1. Buy marginal price will change from 1640 USDC to **1631 USDC** (as it is slowly moving to 1590 USDC)&#x20;

<figure><img src="/files/dUtaHqt1IRFehRdGKT5S" alt=""><figcaption></figcaption></figure>

## Partial Fill

Partial fill represents a case in which the order budget is only partial used.&#x20;

On the strategy overview card, there are two colors:

* Solid color - represents price range area that still has budget&#x20;
* Carbon DeFi moai logo coloring - represents price range area that was used and taken by traders&#x20;

  <figure><img src="/files/IxRvwcWLwr7OtLqa90Tl" alt=""><figcaption></figcaption></figure>

Example:

1. User creates a strategy between ETH/USDC:
   1. Sell 100 ETH between 1650-1700 USDC
   2. Buy ETH with 10,000 USDC budget between 1590-1640 USDC
2. A trader interacted with the Sell order and took 20 ETH from the order
   1. Results in Sell order partial filled as it still holds 80 ETH (out of the initial 100 ETH)

## Fulfillment Dynamics

At some cases, you might see that the market price indication will be "in the money" but no trader is willing to interact with the order. This can happen if the cost of trade is greater than the arbitrage opportunity.&#x20;

Example:

* Market price is at 1641 USDC per ETH
* Sell ETH order between 1635-1645 USDC (indicating the order is "in the money")
* Available liquidity between 1635-1641 USDC is 0.0001 ETH

Result:

The available liquidity is not sufficient to make the trade profitable.


# Strategy ROI

Carbon DeFi is designed to allow traders to set a recurring buy high / sell low trading strategy on chain. Given this ability, it is possible to calculate each strategy's returns (ROI) using the information provided from strategy actions such as creation, balance changes and trades that interact with the available liquidity.

### Disclaimer

The aim is to calculate an ROI figure that is most intuitive to the user based on their performance using Carbon DeFi.

We use a method that utilizes only the current prices of paired tokens, applied historically to every block, and evaluates the returns as a percentage of the liquidity provided.

### Calculating ROI

In order to calculate the strategy ROI, we use the following rules:

1. Only trade events affect the calculation. This means that add/remove liquidity actions will not cause the ROI value to change.
2. We use "sub-strategies" to calculate strategy ROI. Sub-strategies are the times between each balance changing action (add/remove liquidity).&#x20;
3. The strategy ROI is the sum of all the sub-strategy returns (USD) divided by the total liquidity amount deposited (evaluated in USD), provided that the liquidity has been traded with.
4. We use the current USD price of the tokens to calculate "sub-strategy" returns using the historical token amounts against the current USD price.

In order to calculate the ROI, we use this process:

1. Calculate the token gains for every sub-strategy
2. Multiple the token amounts with their current market price to USD
3. Sum the gains USD value and divide it by the strategy value

```
Example:
Start
1 ETH and 1 WBTC
1 ETH @ $2,000 USD = $2,000         # uses the current price today
1 WBTC @ $40,000 USD = $40,000      # uses the current price today
Total value of portfolio is $42,000

The user's order is partially traded against, converting their ETH for WBTC.

End 
0.5 ETH and 1.05 WBTC
0.5 ETH @ $2,000 USD = $1,000        # uses the current price today
1.05 WBTC @ $40,000 USD = $42,000    # uses the current price today
Total value of portfolio is $43,000

Returns: $43,000 - $42,000 = $1,000
ROI: returns / value deposited = 1,000/42,000 = 2.38%
```

Track <https://dune.com/queries/2672807/4443698>


# Limit vs Range Prices

Carbon DeFi offers two distinct trading options, allowing users to trade tokens at either a constant rate or a variable rate. Understanding these options will enable you to make informed trading decisions.

### Price Limit

#### Definition

A trading strategy where users offer to trade tokens at a fixed rate.

#### How it Works

* Users set a specific price at which they wish to trade their tokens.
* This operates similarly to a traditional limit order.
* The offered tokens are available for other market participants to exchange at the specified rate.

#### Example

A user offers to buy ETH at a constant price of 2,000 USDC per ETH. They provide a certain amount of USDC, which will be exchanged at this rate by other traders.

When setting a strategy with a specific price limit, the public indication is similar to limit orders where you indicate that the number of tokens allocated for this action (buy/sell) are available for anyone (traders or market makers) to take at that specific price. It also means that ALL the allocated liquidity will be available at that exact price making it very concentrated at that price point and allowing trade with no slippage against it.

### Price Range

{% hint style="success" %}
The Price Range option is advanced and requires a good understanding of its mechanics.&#x20;
{% endhint %}

#### Definition

A trading strategy where users offer to trade tokens at a variable rate, determined by the remaining quantity of tokens they have.

#### How it Works

* Users set a price range within which they are willing to trade.
* The starting and ending prices of this range are equivalent to the initial and terminal marginal exchange rates.
* As market participants interact with this order, the observed exchange rate adjusts. The observed exchange rate is always equal to the geometric mean of the marginal exchange rates before, and after the swap is performed.

#### Example

A user offers to buy ETH at a price range starting at 2,000 USDC per ETH and ending at 1,000 USDC per ETH. As other market participants exchange their ETH for USDC, the marginal bidding price recedes from 2,000 USDC per ETH down to 1,000 USDC per ETH, until the position's USDC reserves are depleted. &#x20;

When setting a strategy with a price range, the allocated budget will be spread across ALL available price points in the bonding curve that is created between the two price points. Few things to note when using this option:

1. The "average price" for a range is actually the geometric mean, not to be confused with the arithmetic average:

```
Example: 
  Arithmetic mean between 1800-2000 = 1900
   Geometric mean between 1800-2000 = 1897.37
```

2. The amount of price points between 1 DAI value change is 10^18 as there will be a price point for every wei change in price.&#x20;

```
Example:
Between 1800-1801 
1800.000000000000000000
1800.000000000000000001
1800.000000000000000002
1800.000000000000000003
...
1800.999999999999999997
1800.999999999999999998
1800.999999999999999999
1801.000000000000000000
```

3. The budget per price point is sliced very thin.

{% code overflow="wrap" %}

```
Example:
Splitting 100 ETH across 1 DAI price change will split 
100/10^18 = ~0.0000000000000001 ETH per price point 
(this is estimation as due to the curve effect, the distribution is not equal across all price points)
```

{% endcode %}

{% hint style="info" %}
It is recommended to use the price limit option until you are familiar with the math and calculations of the price range option.
{% endhint %}


# Order Execution

Carbon DeFi strategies are created by individual users known as “makers” and composed of one or two onchain limit and range orders. Execution of a maker's orders require the involvement of “takers” -- i.e., spot traders such as direct traders on [app.carbondefi.xyz/trade](https://app.carbondefi.xyz/trade), arbitrageurs and DEX aggregators.

The settings of each user's strategy, the strategy's liquidity, total network liquidity in the token pair, as well as network congestion affect the likelihood of execution in their strategy.&#x20;

### Liquidity and Ranges

Makers submit orders with their custom ranges defining the prices at which they’re willing to buy or sell their tokens. An order with a relatively wide range spreads liquidity across a larger number of prices, whereas an order with a relatively tight range concentrates liquidity within a smaller number of prices. Orders with more liquidity concentrated at a given price are more likely to get their orders executed when the market moves into that price.

For example, consider two separate Carbon DeFi orders to buy ETH using USDC. Both orders are funded with the same amount of USDC tokens, but have different sized ranges. \
Jen's `Order A` offers to buy ETH in the range of 1800-1900 USDC. \
Tom's `Order B` offers to buy ETH in the range of 1800-2000 USDC. \
\
Jen's order slices the allocated budget across a tighter range, which means more tokens per each price point in the range.\
\
When the external market price of ETH reaches 1800, Jen's `Order A` is more likely to execute first, since it has a larger amount of liquidity concentrated at 1800 and can therefore offer a better price to the taker.

### Gas

Gas cost is also factored into spot trading requests submitted to Carbon DeFi. A maker order may be offering a price that is desirable for takers, however the gas costs involved with filling the trade may make the trade undesirable, resulting in non-execution. The same holds true for arbitrageurs. Typically an arb takes trades on Carbon DeFi (and executes the relevant maker order) if it is profitable for the arb to do so, and such profit measurements include the current cost of gas.


# 100% Fill Estimation

When creating a new strategy or editing an existing one, a value called "100% filled estimation" is exposed for ease of use.&#x20;

### Goal of estimation

The 100% filled estimation is an indication to makers on the amount of tokens the strategy will hold, should the entire budget be used. Once the order(s) details are provided, the buy or sell average price is identified and multiplied by the entire budget.

### Calculation

#### Price aspect

1. Limit - when entering a limit price, the average execution price is identical to the indicated price.
2. Range - when entering price range, the cost basis for the specified range is equal to the geometric mean of the highest and lowest price boundaries of the indicated range.

$$
GeometricMean =\sqrt{(minPrice)\*(maxPrice)}
$$

#### Budget aspect

Budget indicates the amount of tokens allocated to each order. This is a base value that will be used against the indicated price mentioned above.

#### 100% fill calculation

Using the values from [`Price`](#price-aspect) \* [`Budget`](#budget-aspect) results in the estimated 100% fill value.

### Notice

As orders within a recurring strategy are traded against and refilled, 100% fill estimation results may change.


# Resources

* ​[Carbon DeFi Website](https://www.carbondefi.xyz/)
* [Blog](https://medium.com/carbondefi)
* [Dune Analytics](https://dune.com/bancor/carbon-by-bancor)
* [Technical Documentation​](https://docs.carbondefi.xyz/contracts-and-functions/contracts)
* ​[Github](https://github.com/bancorprotocol/carbon-contracts)​
* ​[Whitepaper](http://carbondefi.xyz/whitepaper)​
* ​[Litepaper](http://carbondefi.xyz/litepaper)​
* ​[Trading Simulator](https://github.com/bancorprotocol/carbon-simulator)
* [Carbon DeFi Twitter](https://twitter.com/carbondefixyz)​​
* ​[YouTube](https://www.youtube.com/@BancorProtocol)
* [Brand Kit​](https://www.carbondefi.xyz/brand)


# The Bancor Ecosystem & Carbon DeFi

[Bancor](http://bancor.network) is an ecosystem of decentralized, open-source protocols that promote onchain trading and liquidity.

[Carbon](https://carbondefi.xyz/)[ DeFi](https://www.carbondefi.xyz/) has been [proposed](https://gov.bancor.network/t/proposing-carbon-final/4242) as Bancor's flagship offering.

[Arb Fast Lane](https://bancor.network/arb-fast-lane), a decentralized arbitrage protocol, allows any user to perform arbitrage between DEXes chain-wide.

All Bancor ecosystem protocols, including Carbon DeFi and Arb Fast Lane, are governed by the [BancorDAO](https://gov.bancor.network/) via staked BNT.


# Blockchain Data

The CarbonDeFi.xyz app relies mostly on blockchain data that is available to all.&#x20;

In order to maintain close to real-time data availability, the CarbonDeFi.xyz app utilizes [Alchemy](https://alchemy.com/?r=08526d9e-6b37-420c-9218-8d06a7cbdf7a) as they provide leading service for real-time blockchain data and information.&#x20;


