MarginX 2.0 gitbook v1.1
  • 🚀Getting Started: MarginX 2.0
  • MARGINX 2.0 & ALO
    • Vision
    • Mechanic & Foundation of ALO
    • Comparison Between Order Book And Swap
    • Risk and Reward of Liquidity Providers
    • Product Comparison
    • MarginX ALO: Whitepaper
  • Technical structure
    • Contract Structure
      • CoastDAO Module
    • The Fund Module
      • Contract Specific Design
      • Cross-Chain Description
    • Contract Events
      • Strategy Factory
      • Strategy Pair
      • DssCdpManager
      • DSProxyFactory
      • Vat
    • Contract Invocation Method
      • DSProxyFactory
      • ProxyRegistry
      • DSProxy
      • The Price of the Collateral Assets
      • DssProxyActions
        • Adding Liquidity For New Perpetual Markets (First Time)
        • Creating Order (Providing Liquidity)
        • Request For Withdrawing Liquidity
        • Withdrawal
      • StrategyFactory
  • MarginX Spot
    • Swap
    • Pool
      • Add Liquidity
      • Remove Liquidity
    • Farm
      • Deposit LP Tokens
      • Withdraw LP Token
    • Supported Networks
  • MARGINX SUBGRAPH
    • Overview
    • Query Examples
  • MarginX 1.0
    • Built On f(x)Core
    • Decentralized Order Book
    • Referral Programme
    • MarginX NFTs
    • Maker Liquidity Pool
    • MarginX 1.0 Litepaper
  • ERC20 Token Factory
    • Token Factory Supported Networks
    • Create Token
    • Provide Token Details
    • Interact with Token
    • Role Management
  • Help desk
    • Perpetual Trading 101
    • User Guide (Video)
    • MarginX 2.0 FAQ
    • Contact us
Powered by GitBook
On this page
  1. Technical structure
  2. The Fund Module

Cross-Chain Description

Before delving into the cross-chain details, let's establish some conditions:

Predefined Trading Pairs and Trading Strategies:

A. The contract should define the trading pairs and trading strategies that can be created in advance.

B. Pre-generated MarginX Liquidity Provider Addresses: Addresses of liquidity providers for MarginX should be generated in advance and fed into the contract.

The contract interacts with MarginX through three primary cross-chain mechanisms:

1. Creating a Strategy:

a. Factory Address Authorization:

- The contract must pre-add the addresses of liquidity provider factories.

- MarginX needs to verify that the transaction comes from an authorized factory address and only accepts transactions from the factory address for creating strategies.

b. IBC Cross-Chain Data Transfer for Strategy Creation:

- When creating a strategy, the contract sends an IBC cross-chain message to the corresponding liquidity provider's address.

- The data transmitted includes information such as:

- pair_id: The trading pair identifier (e.g., ETH:CUSD).

- pair_address: The address of the pair contract (MarginX should match this pair address with the respective liquidity provider).

c. Initial Funding of the Strategy:

- Simultaneously with strategy creation, the contract transfers at least 1000 CUSD to the corresponding liquidity provider's address.

2. Adding Liquidity and Withdrawing Liquidity:

a. Periodic IBC Messages to MarginX:

- To facilitate accurate fund net value calculations, the contract periodically sends IBC messages to MarginX's address.

b. Details of the Cross-Chain Message:

- The cross-chain message contains the following information:

i. Sent by the pair address matched with the liquidity provider.

ii. Cross-chain transfer of stablecoins to the corresponding liquidity provider's address.

iii. Aggregation of LP tokens from orders that need to be withdrawn (total LP token shares).

MarginX processes this data to:

i. Calculate the fund net value.

ii. Perform cross-chain transfers of stablecoins to the contract.

iii. Update the fund net value in the contract.

This process ensures that both sides have matching information, reduces the quantity of IBC messages, and allows users to withdraw based on the updated fund net value.

3. Periodic Fund Net Value Updates:

If there is a prolonged period without additions or withdrawals of liquidity orders that need updating, the contract should periodically update the corresponding fund net value.

These cross-chain mechanisms are designed to maintain consistency and accuracy in fund net value calculations while minimizing the number of cross-chain transactions. This approach benefits both sides by ensuring that users can withdraw the actual amount they are entitled to based on the most recent fund net value update.

PreviousContract Specific DesignNextContract Events

Last updated 1 year ago