Skip to content

Commit

Permalink
Update v2.md
Browse files Browse the repository at this point in the history
  • Loading branch information
vuong177 authored Oct 2, 2024
1 parent 29d7a7e commit 306a43b
Showing 1 changed file with 125 additions and 1 deletion.
126 changes: 125 additions & 1 deletion docs/v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,128 @@ flowchart TD
IBC close channel logic is considered similar to zero max cap logic. When close channel, the consumer chain will query `AllDelegations` to get all delegations in KV store. The virtual staking contract will unbond all tokens and dispatch `Unbond` msg to mesh security module. After that, a `OnChannelCloseConfirm` will be send to provider chain. The vault contract will execute `handle_channel_close` function, which unbond all tokens in provider chain from external staking contract.

#### PR for the issue
- Contract: [mesh-security#203](https://github.com/osmosis-labs/mesh-security/pull/203)
- Contract: [mesh-security#203](https://github.com/osmosis-labs/mesh-security/pull/203)

### [Using async icq for osmosis price feeder](https://github.com/osmosis-labs/mesh-security/pull/206)

In [v0.10.0-alpha](https://github.com/osmosis-labs/mesh-security/releases/tag/v0.10.0-alpha.1), mesh security uses two contracts to get osmosis price data (one on the consumer side and one on the osmosis side). The osmosis price provider is only used for query twap price directly from osmosis chain.

We can simplify this process by using async-icq and remove the osmosis price provider contract.

To achieve this, the port forwarding to the Osmosis chain should be set to **`icqhost`**, and the version should be **`icq-1`**. Additionally, the IBC packet for the Osmosis price feeder needs modification. Instead of sending the **`ArithmeticTwapToNowRequest`** packet directly to the Osmosis price provider contract, it should be wrapped in the **`CosmosQuery`** struct. The acknowledgment packet should also be deserialized to the **`AcknowledgementResult`** struct.

#### Flow
```mermaid
%%{init: {'theme': 'forest'}}%%
flowchart TD
A(Meshconsumer chain) -- 1. Send handle epoch msg --> B(Converter contract);
B -- 2. Execute handle epoch --> C(Osmosis price feeder contract);
C -- 3. Check if price is outdate --> C;
C -- 4. Send query twap request IBC packet --> D(Osmosis chain);
D -- 5. Ack twap price data --> C;
```

#### Messages
1. Sending packet

CosmosQuery:
|Parameters| Type |
|----------|------------------|
|requests | Vec<RequestQuery>|


RequestQuery (tendermint.abci.RequestQuery):
|Parameters| Type | Info |
|----------|--------|------|
|data | Vec<u8> | refer to **`ArithmeticTwapToNowRequest`** |
|path | String | must be **`/osmosis.twap.v1beta1.Query/ArithmeticTwapToNow`**|
|height | i64 | must be 0 (we don't need to update this) |
|prove | bool | must be false (we don't need to update this)|

ArithmeticTwapToNowRequest:
|Parameters | Type |
|------------|----------|
| pool_id | u64 |
| base_asset | String |
| quote_asset| String |
| start_time | Timestamp|

2. Receiving ack

AcknowledgementResult:
|Parameters | Type | Info |
|------------|----------|------|
| result | cosmwasm_std.Binary | refer to **`InterchainQueryPacketAck`** |

InterchainQueryPacketAck:
|Parameters | Type | Info |
|------------|----------|------|
| data | cosmwasm_std.Binary | refer to **`QueryArithmeticTwapToNowResponse`** |

QueryArithmeticTwapToNowResponse:
|Parameters | Type |
|---------------|----------|
|arithmetic_twap| String |

### [Band price feeder](https://github.com/osmosis-labs/mesh-security/pull/195)

The band price feeder is designed similar to osmosis price feeder, but secified to query price in Band oracle. The packet **`OracleRequestPacketData`** send to band chain is specified designed for oracle module. Its ack packet will not return price immediately, so we need to wait for receiving and updating price on **`OnReceiveIBCPacket`**. Also, port forwarding to the Band chain should be set to **`oracle`**, and the version should be **`bandchain-1`**.

#### Flow
```mermaid
%%{init: {'theme': 'forest'}}%%
flowchart TD
A(Meshconsumer chain) -- 1. Send handle epoch msg --> B(Converter contract);
B -- 2. Execute handle epoch --> C(Band price feeder contract);
C -- 3. Check if price is outdate --> C;
C -- 4. Send query oracle price IBC packet --> D(Bandchain);
D -- 5. Acknowledge request --> C;
D -- 6. Send oracle price packet --> C;
```

#### Messages
1. Sending packet

OracleRequestPacketData:
|Parameters | Type | Info |
|-----------------|----------|------|
| client_id | String | Client id of the mesh security chain |
| oracle_script_id| Uint64 | The data source's id you choose |
| calldata | Binary | Refer to cw_band.Input |
| ask_count | Uint64 | The number of validator you want to ask (Recommend: 4 on testnet) |
| min_count | Uint64 | The minimum number of validator need to answer to aggregate result (Recommend: 3 on testnet)|
| fee_limit | Vec<Coin>| Data source fee that you willing to pay (Recommend: 250000uband) |
| prepare_gas | Uint64 | Gas for running prepare phrase (Recommend: 100000) |
| execute_gas | Uint64 | Gas for running execute phrase (Recommend: 500000) |


cw_band.Input:
|Parameters | Type | Info |
|-----------------|------------|------|
| symbols | Vec<String>| Should only contains base_asset and quote_asset|
| minimum_sources | u8 | The minimum available sources to determine price is aggregated from at least minimum sources (for data integrity) 1 should be ok for testing |

2. Receiving packet

OracleResponsePacketData:

|Parameters | Type | Info |
|-----------------|------------|------|
| client_id | String | |
| request_id | Uint64 | |
| ans_count | Uint64 | |
| request_time | Uint64 | |
| resolve_time | Uint64 | |
| result | Binary | Refer to cw_band.Output |

cw_band.Output:
|Parameters | Type |
|-----------------|-------------|
| responses |Vec<Response>|

Response:
|Parameters | Type |
|-----------------|-------------|
| symbol | String |
| response_code | u8 |
| rate | u64 |

0 comments on commit 306a43b

Please sign in to comment.