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.

Last updated