Trait hydradx_traits::AMM
source · pub trait AMM<AccountId, AssetId, AssetPair, Amount: Zero> {
Show 16 methods
fn exists(assets: AssetPair) -> bool;
fn get_pair_id(assets: AssetPair) -> AccountId;
fn get_share_token(assets: AssetPair) -> AssetId;
fn get_pool_assets(pool_account_id: &AccountId) -> Option<Vec<AssetId>>;
fn get_spot_price_unchecked(
asset_a: AssetId,
asset_b: AssetId,
amount: Amount
) -> Amount;
fn validate_sell(
origin: &AccountId,
assets: AssetPair,
amount: Amount,
min_bought: Amount,
discount: bool
) -> Result<AMMTransfer<AccountId, AssetId, AssetPair, Amount>, DispatchError>;
fn execute_sell(
transfer: &AMMTransfer<AccountId, AssetId, AssetPair, Amount>
) -> DispatchResult;
fn validate_buy(
origin: &AccountId,
assets: AssetPair,
amount: Amount,
max_limit: Amount,
discount: bool
) -> Result<AMMTransfer<AccountId, AssetId, AssetPair, Amount>, DispatchError>;
fn execute_buy(
transfer: &AMMTransfer<AccountId, AssetId, AssetPair, Amount>
) -> DispatchResult;
fn get_min_trading_limit() -> Amount;
fn get_min_pool_liquidity() -> Amount;
fn get_max_in_ratio() -> u128;
fn get_max_out_ratio() -> u128;
fn get_fee(pool_account_id: &AccountId) -> (u32, u32);
fn sell(
origin: &AccountId,
assets: AssetPair,
amount: Amount,
min_bought: Amount,
discount: bool
) -> DispatchResult { ... }
fn buy(
origin: &AccountId,
assets: AssetPair,
amount: Amount,
max_limit: Amount,
discount: bool
) -> DispatchResult { ... }
}
Expand description
Traits for handling AMM Pool trades.
Required Methods§
sourcefn get_pair_id(assets: AssetPair) -> AccountId
fn get_pair_id(assets: AssetPair) -> AccountId
Return pair account.
Return share token for assets.
sourcefn get_pool_assets(pool_account_id: &AccountId) -> Option<Vec<AssetId>>
fn get_pool_assets(pool_account_id: &AccountId) -> Option<Vec<AssetId>>
Return list of active assets in a given pool.
sourcefn get_spot_price_unchecked(
asset_a: AssetId,
asset_b: AssetId,
amount: Amount
) -> Amount
fn get_spot_price_unchecked(
asset_a: AssetId,
asset_b: AssetId,
amount: Amount
) -> Amount
Calculate spot price for asset a and b.
sourcefn validate_sell(
origin: &AccountId,
assets: AssetPair,
amount: Amount,
min_bought: Amount,
discount: bool
) -> Result<AMMTransfer<AccountId, AssetId, AssetPair, Amount>, DispatchError>
fn validate_sell(
origin: &AccountId,
assets: AssetPair,
amount: Amount,
min_bought: Amount,
discount: bool
) -> Result<AMMTransfer<AccountId, AssetId, AssetPair, Amount>, DispatchError>
Sell trade validation Perform all necessary checks to validate an intended sale.
sourcefn execute_sell(
transfer: &AMMTransfer<AccountId, AssetId, AssetPair, Amount>
) -> DispatchResult
fn execute_sell(
transfer: &AMMTransfer<AccountId, AssetId, AssetPair, Amount>
) -> DispatchResult
Execute buy for given validated transfer.
sourcefn validate_buy(
origin: &AccountId,
assets: AssetPair,
amount: Amount,
max_limit: Amount,
discount: bool
) -> Result<AMMTransfer<AccountId, AssetId, AssetPair, Amount>, DispatchError>
fn validate_buy(
origin: &AccountId,
assets: AssetPair,
amount: Amount,
max_limit: Amount,
discount: bool
) -> Result<AMMTransfer<AccountId, AssetId, AssetPair, Amount>, DispatchError>
Buy trade validation Perform all necessary checks to validate an intended buy.
sourcefn execute_buy(
transfer: &AMMTransfer<AccountId, AssetId, AssetPair, Amount>
) -> DispatchResult
fn execute_buy(
transfer: &AMMTransfer<AccountId, AssetId, AssetPair, Amount>
) -> DispatchResult
Execute buy for given validated transfer.
fn get_min_trading_limit() -> Amount
fn get_min_pool_liquidity() -> Amount
fn get_max_in_ratio() -> u128
fn get_max_out_ratio() -> u128
fn get_fee(pool_account_id: &AccountId) -> (u32, u32)
Provided Methods§
sourcefn sell(
origin: &AccountId,
assets: AssetPair,
amount: Amount,
min_bought: Amount,
discount: bool
) -> DispatchResult
fn sell(
origin: &AccountId,
assets: AssetPair,
amount: Amount,
min_bought: Amount,
discount: bool
) -> DispatchResult
Perform asset swap. Call execute following the validation.
sourcefn buy(
origin: &AccountId,
assets: AssetPair,
amount: Amount,
max_limit: Amount,
discount: bool
) -> DispatchResult
fn buy(
origin: &AccountId,
assets: AssetPair,
amount: Amount,
max_limit: Amount,
discount: bool
) -> DispatchResult
Perform asset swap.