Permissionless Pool Creation
The Pool
shared object represents a market, such as a SUI/USDC market. That Pool
is the only one representing that unique pairing (SUI/USDC) and the pairing is the only member of that particular Pool
. See DeepBook Design to learn more about the structure of pools.
API
Create a Pool
The create_permissionless_pool()
function creates a Pool
public fun create_permissionless_pool<BaseAsset, QuoteAsset>(
registry: &mut Registry,
tick_size: u64,
lot_size: u64,
min_size: u64,
creation_fee: Coin<DEEP>,
ctx: &mut TxContext,
): ID {
assert!(creation_fee.value() == constants::pool_creation_fee(), EInvalidFee);
let base_type = type_name::get<BaseAsset>();
let quote_type = type_name::get<QuoteAsset>();
let whitelisted_pool = false;
let stable_pool = registry.is_stablecoin(base_type) && registry.is_stablecoin(quote_type);
create_pool<BaseAsset, QuoteAsset>(
registry,
tick_size,
lot_size,
min_size,
creation_fee,
whitelisted_pool,
stable_pool,
ctx,
)
}
Tick size should be 10^(9 - base_decimals + quote_decimals - decimal_desired). For example, if creating a SUI(9 decimals)/USDC(6 decimals) pool, with a desired decimal of 3 for tick size (0.001), tick size should be 10^(9 - 9 + 6 - 3) = 10^(3) = 1000.
Decimal desired should be at most 1bps, or 0.01%, of the price between base and quote asset. For example, if 3 decimals is the target, 0.001 (three decimals) / price should be less than or equal to 0.0001. Consider a lower tick size for pools where both base and quote assets are stablecoins.
Lot size is in MIST of the base asset, and should be approximately $0.01 to $0.10 nominal of the base asset. Lot size must be a power of 10, and less than or equal to min size. Lot size should also be greater than or equal to 1,000.
Min size is in MIST of the base asset, and should be approximately $0.10 to $1.00 nominal of the base asset. Min size must be a power of 10, and larger than or equal to lot size.
Creation fee is 500 DEEP tokens.
Pools can only be created if the asset pair has not already been created before.
Add DEEP price point
The add_deep_price_point()
function allows for the calculation of DEEP price and correct collection of fees in DEEP.
public fun add_deep_price_point<BaseAsset, QuoteAsset, ReferenceBaseAsset, ReferenceQuoteAsset>(
target_pool: &mut Pool<BaseAsset, QuoteAsset>,
reference_pool: &Pool<ReferenceBaseAsset, ReferenceQuoteAsset>,
clock: &Clock,
) {
assert!(
reference_pool.whitelisted() && reference_pool.registered_pool(),
EIneligibleReferencePool,
);
let reference_pool_price = reference_pool.mid_price(clock);
let target_pool = target_pool.load_inner_mut();
let reference_base_type = type_name::get<ReferenceBaseAsset>();
let reference_quote_type = type_name::get<ReferenceQuoteAsset>();
let target_base_type = type_name::get<BaseAsset>();
let target_quote_type = type_name::get<QuoteAsset>();
let deep_type = type_name::get<DEEP>();
let timestamp = clock.timestamp_ms();
assert!(
reference_base_type == deep_type || reference_quote_type == deep_type,
EIneligibleTargetPool,
);
let reference_deep_is_base = reference_base_type == deep_type;
let reference_other_type = if (reference_deep_is_base) {
reference_quote_type
} else {
reference_base_type
};
let reference_other_is_target_base = reference_other_type == target_base_type;
let reference_other_is_target_quote = reference_other_type == target_quote_type;
assert!(
reference_other_is_target_base || reference_other_is_target_quote,
EIneligibleTargetPool,
);
let deep_per_reference_other_price = if (reference_deep_is_base) {
math::div(1_000_000_000, reference_pool_price)
} else {
reference_pool_price
};
target_pool
.deep_price
.add_price_point(
deep_per_reference_other_price,
timestamp,
reference_other_is_target_base,
);
emit_deep_price_added(
deep_per_reference_other_price,
timestamp,
reference_other_is_target_base,
reference_pool.load_inner().pool_id,
target_pool.pool_id,
);
}
All pools support input token fees. To allow a permissionless pool to pay fees in DEEP, which has a 20% discount compared to input token fees, two conditions must be met:
- Either the base or quote asset must be
USDC
orSUI
. - To calculate DEEP fees accurately, you must set up a cron job to call the
add_deep_price_point()
function on the pool every 1-10 minutes.
For a pool with USDC
as an asset, use the DEEP/USDC
pool at 0xf948981b806057580f91622417534f491da5f61aeaf33d0ed8e69fd5691c95ce
as the reference pool.
For a pool with SUI
as an asset, use the DEEP/SUI
pool at 0xb663828d6217467c8a1838a03793da896cbe745b150ebd57d82f814ca579fc22
as the reference pool.