Skip to content
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

Flowchain Runtime Design V1 #7

Closed
xlc opened this issue Nov 19, 2019 · 0 comments
Closed

Flowchain Runtime Design V1 #7

xlc opened this issue Nov 19, 2019 · 0 comments

Comments

@xlc
Copy link
Collaborator

xlc commented Nov 19, 2019

Flowchain Runtime Design

  • V1: Basic features
  • V2: Permissions control for liquidity pool
  • V3: Smart contracts integration

Flowchain Runtime Modules V1

  • primitives
    • type LiquidityPoolId = u32
    • enum CurrencyId
      • FLOW
      • AUSD
      • FEUR
      • FJPY
    • bitmask Leverages
      • flag enum Leverage: u16
        • Five
        • Ten
        • Twenty
        • Thirty
        • Forty
        • Fifty
  • liuqidity_pools
    • Types
      • struct LiquidityPoolOption
        • bidSpread: Permill
        • askSpread: Permill
        • additionalCollateralRatio: Option<Permill>
        • enabledLongs: Leverages
        • enabledShorts: Leverages
      • trait LiquidityPoolManager
        • fn can_remove(pool: LiquidityPoolId) -> bool
    • Trait
      • Currency: BasicCurrency
        • USD Stablecoin Currency
      • LiquidityPoolManager: LiquidityPoolManager
    • Storage
      • NextPoolId: Option<LiquidityPoolId>
      • Owners: map LiquidityPoolId => Option<AccoundId>
      • LiquidityPoolOptions: double_map LiquidityPoolId, CurrencyId => Option<LiquidityPool>
    • Constant
      • ExistentialDeposit: Balance
        • Minimumal amount of deposits to maintain a liquidity pool
        • User cannot drawn liquidity pool to below this amount, unless they use remove_pool to withdraw all funds
    • Call
      • create_pool(origin)
        • Create a new liquidity pool
      • disable_pool(origin, pool: LiquidityPoolId)
        • Disable all tokens for this pool
        • Require owner
        • Reset EnabledTrades
      • remove_pool(origin, pool: LiquidityPoolId)
        • Withdraw all liquidity and remove this pool
        • Require owner & No outstanding positions
        • Use LiquidityPoolManager to perform check
      • deposit_liquidity(origin, pool: LiquidityPoolId, amount: Balance)
        • Add money to this pool
        • No need to check owner
      • withdraw_liquidity(origin, pool: LiquidityPoolId, amount: Balance)
        • Withdraw money from this pool
        • Require owner
        • Require remaining above ExistentialDeposit
      • set_bid_spread(origin, pool: LiquidityPoolId, currency_id: CurrencyId, ask: Permill, bid: Permill)
        • Set Ask & Bid spread
        • Require owner
      • set_additional_collateral_ratio(origin, pool: LiquidityPoolId, currency_id: CurrencyId, ratio: Option<Permill>)
        • Set additonal colalteral ratio
        • Require owner
      • set_enabled_trades(origin, pool: LiquidityPoolId, currency_id: CurrencyId, long: Leverages, short: Leverages)
        • Set enabled longs & enabled shorts
        • Require owner
    • Module
      • is_owner(pool: LiquidityPoolId, who: AccountId)
      • Is_enabled(pool: LiquidityPoolId, currency_id: CurrencyId, leverage: i8)
        • spot is leverage = 1
  • synthetic_tokens
    • Types
      • struct Position
        • collaterals: Balance
        • minted: Balance
    • Trait
      • Currency: MultiCurrency
    • Storage
      • ExtremeRatio: CurrencyId => Option<Permill>
      • LiquidationRatio: CurrencyId => Option<Permill>
      • CollateralRatio: CurrencyId => Option<Permill>
      • Positions: map (LiquidityPoolId, CurrencyId) => Position
    • Constant
      • DefaultExtremeRatio: Permill
      • DefaultLiquidationRatio: Permill
      • DefaultCollateralRatio: Permill
    • Module
      • addPosition(who: AccountId, pool: LiquidityPoolId, collaterals: Balance, minted: Balance)
      • removePosition(who: AccountId, pool: LiquidityPoolId, collaterals: Balance, minted: Balance)
  • synthetic_protocol
    • Types
    • Trait
      • CurrencyId
      • PriceProvider: PriceProvider
    • Constant
      • MaxSpread: Permill
    • Call
      • mint(origin, currency_id: CurrencyId, pool: LiquidityPoolId, collateral: Balance, max_slippage: Permill)
      • redeem(origin, currency_id: CurrencyId, pool: LiquidityPoolId, synthetic: Balance, max_slippage: Permill)
      • liquidate(origin, currency_id: CurrencyId, pool: LiquidityPoolId, synthetic: Balance)
      • add_collateral(currency_id: CurrencyId, pool: LiquidityPoolId, collateral: Balance)
      • withdraw_collateral(currency_id: CurrencyId)
    • Module
  • margin_protocol
    • Types
      • struct TradingPair
        • quote: CurrencyId
        • leverage: i8
      • type PositionId = u64
      • struct Position
        • owner: AccountId
        • pool: LiquidityPoolId
        • amount: Balance
          • one side amount, fee included
        • openPrice: Price
        • closeSpread: Permill
    • Trait
      • PriceProvider: PriceProvider
    • Storage
      • NextPositionId: PositionId
      • Positions: map PositionId => Option<Position>
    • Constant
      • LiquidationFee: Balance
      • SafeMarginPercent: Permill
    • Call
      • openPosition(origin, pair: TradingPair, pool: LiquidityPoolId, base_amount: Balance)
      • closePosition(origin, position_id: PositionId)
    • Module

TODOs:

  • Think bit more about liquidations for synthetic & margin protocols
    • synthetic
      • Extreme collateral ratio
      • Liquidation collateral ratio
    • margin
      • Liquidation fee
      • Safe margin percent
    • Perform check on-chain?
    • Perform check off-chain with offchain worker?
      • How to incentive nodes / validators?
@xlc xlc changed the title Flowchain Runtime Design WIP Flowchain Runtime Design V1 Nov 19, 2019
@xlc xlc closed this as completed Feb 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant