Skip to content

Commit

Permalink
imp: ran 'npm run docusaurus docs:version v0.5.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed Mar 25, 2024
1 parent 8846b82 commit c458273
Show file tree
Hide file tree
Showing 16 changed files with 761 additions and 3 deletions.
10 changes: 7 additions & 3 deletions docs/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,24 @@ const config: Config = {
// Please change this to your repo.
// Remove this to remove the "edit this page" links.
editUrl:
'https://github.com/srdtrk/cw-ica-controller/tree/feat/docusaurus-docs/docs',
'https://github.com/srdtrk/cw-ica-controller/tree/main/docs',
// Routed the docs to the root path
routeBasePath: "/",
sidebarCollapsed: false,
// Select the latest version
lastVersion: "v0.4.x",
lastVersion: "v0.5.x",
versions: {
current: {
label: 'main',
path: 'main',
banner: 'unreleased',
},
"v0.5.x": {
label: 'v0.5.x',
path: 'v0.5',
},
"v0.4.x": {
label: 'v0.4',
label: 'v0.4.x',
path: 'v0.4',
},
},
Expand Down
43 changes: 43 additions & 0 deletions docs/versioned_docs/version-v0.5.x/00-intro.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
title: Introduction
sidebar_label: Introduction
sidebar_position: 0
slug: /
---

import HighlightTag from '@site/src/components/HighlightTag';

# CosmWasm ICA Controller

<HighlightTag type="concepts"/><HighlightTag type="basics"/>

Welcome to the documentation for CosmWasm Interchain Accounts Controller. This document will guide you through
understanding the [ICS-27](https://github.com/cosmos/ibc/tree/main/spec/app/ics-027-interchain-accounts)
Interchain Accounts protocol and how to use `cw-ica-controller` to create and manage interchain accounts on
any IBC enabled CosmWasm chain.

The CosmWasm ICA Controller is a CosmWasm contract that implements the ICS-27 interchain accounts controller in
pure Rust. It is designed to be used by other CosmWasm contracts to create and manage interchain accounts on
the chain where the contract is deployed.

## High Level Overview

The following diagram shows how `cw-ica-controller` works at a high level.

![High Level Overview](/img/cw-ica-controller.svg)

The `cw-ica-controller` contract code is deployed on a chain that supports IBC CosmWasm. This chain does not need
to support ICS-27 interchain accounts nor does it need to support any custom IBC bindings. Then when an external
account or a contract instantiates a `cw-ica-controller` contract, the contract will initiate the ICS-27 handshake
with a chain that supports ICS-27 interchain accounts based on the options provided by the caller.

:::note

The counterparty chain need not be a CosmWasm chain. It can be any chain that uses ibc-go and supports `ICS-27`.
Such as CosmosHub, Osmosis, etc.

:::

Then the rest of the ICS-27 handshake is completed by the relayers automatically. Both the hermes relayer and the
go relayer support `ICS-27` interchain accounts. Once the handshake is complete, the `cw-ica-controller` contract
makes a callback to the callback contract if one was provided during instantiation.
22 changes: 22 additions & 0 deletions docs/versioned_docs/version-v0.5.x/contract-api/00-intro.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: Contract API
sidebar_label: Overview
sidebar_position: 0
slug: /contract-api/intro
---

import HighlightTag from '@site/src/components/HighlightTag';

# Contract API

<HighlightTag type="developer"/>

In this section we will cover how to interact with the contract and design decisions that were made. A full integration guide is work in progress.

In this section, we cover the following topics:

- ✉️ [`InstantiateMsg`](./01-instantiate-msg.mdx)
- 📨 [`ExecuteMsg`](./02-execute-msg.mdx)
- 🤔 [`QueryMsg`](./03-query-msg.mdx)
- 🤙 [Callbacks](./04-callbacks.mdx)
- 📜 [Events](./05-events.mdx)
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
title: InstantiateMsg
sidebar_label: InstantiateMsg
sidebar_position: 1
slug: /contract-api/instantiate-msg
---

# `InstantiateMsg`

The `InstantiateMsg` is the message that is used to instantiate the `cw-ica-controller` contract.

```rust reference
https://github.com/srdtrk/cw-ica-controller/blob/v0.5.0/src/types/msg.rs#L8-L21
```

## Fields

### `owner`

This contract has an owner who is allowed to call the `ExecuteMsg` methods.
The owner management is handled by the amazing [cw-ownable](https://crates.io/crates/cw-ownable) crate.
If left empty, the owner is set to the sender of the `InstantiateMsg`.

### `channel_open_init_options`

```rust reference
https://github.com/srdtrk/cw-ica-controller/blob/v0.5.0/src/types/msg.rs#L124-L140
```

These are the options required for the contract to initiate an ICS-27 channel open handshake.
This contract requires there to be an IBC connection between the two chains before it can open a channel.

#### `connection_id`

The identifier of the IBC connection end on the deployed (source) chain. (The underlying IBC light client must
be live.) If this field is set to a non-existent connection, the execution of the `InstantiateMsg` will fail.

#### `counterparty_connection_id`

The identifier of the IBC connection end on the counterparty (destination) chain. (The underlying IBC light
client must be live.) If this field is set to a non-existent connection or a different connection's end,
then the execution of the `InstantiateMsg` will not fail. This is because the source chain does not know
about the counterparty chain's connections. Instead, the channel open handshake will fail to complete.

If the contract was instantiated with a `counterparty_connection_id` that does not match the connection
end on the counterparty chain, then the owner must call [`ExecuteMsg::CreateChannel`](./02-execute-msg.mdx#createchannel) with the correct parameters to start a new channel open handshake.

#### `counterparty_port_id`

This is a required parameter for the ICS-27 channel version metadata. I've added it here for consistency.
Currently, the only supported value is `icahost`. If left empty, it is set to `icahost`.
**So you should ignore this field.**

#### `tx_encoding`

The ICS-27 implementation in `ibc-go` supports two transaction encoding formats: `proto3` and `proto3json`.
This contract supports both formats, but defaults to `proto3`. This is because most chains don't yet support
`proto3json` encoding. Moreover, this contract does not support some `CosmosMsg` while using `proto3json`.
**So, if you are unsure, leave this field empty.**

### `send_callbacks_to`

This is the address of the contract that will receive the callbacks from the `cw-ica-controller` contract.
This may be the same address as the `owner` or a different address. If left empty, no callbacks will be sent.
Learn more about callbacks [here](./04-callbacks.mdx).
135 changes: 135 additions & 0 deletions docs/versioned_docs/version-v0.5.x/contract-api/02-execute-msg.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
---
title: ExecuteMsg
sidebar_label: ExecuteMsg
sidebar_position: 2
slug: /contract-api/execute-msg
---

# `ExecuteMsg`

The `ExecuteMsg` is the message that is used to interact with the `cw-ica-controller` contract.
**All execute messages are only callable by the owner of the contract.**

## `CreateChannel`

```rust reference
https://github.com/srdtrk/cw-ica-controller/blob/v0.5.0/src/types/msg.rs#L27-L37
```

This message is used to initiate an ICS-27 channel open handshake. It is only callable by the owner.
This message only takes one optional parameter: `channel_open_init_options`.

If this parameter is left empty, then the contract will use the `channel_open_init_options` that were last
passed to the `InstantiateMsg` or `CreateChannel` messages.

If this parameter is set, then the contract will use the `channel_open_init_options` that are passed to this
message and save them for future `CreateChannel` messages.

## `CloseChannel`

```rust reference
https://github.com/srdtrk/cw-ica-controller/blob/v0.5.0/src/types/msg.rs#L38-L39
```

This message is used to close the ICS-27 channel. It is only callable by the owner.
The channel can then be reopened with parameters (e.g. channel ordering and version) that are different from the
original channel open handshake.

## `SendCosmosMsgs`

```rust reference
https://github.com/srdtrk/cw-ica-controller/blob/v0.5.0/src/types/msg.rs#L40-L54
```

Once an ICS-27 channel open handshake is complete, the owner can control the interchain account on the counterparty
chain. To give the owner a familiar interface, this message allows the owner to take actions with the interchain
account using `CosmosMsg`s. This is the recommended way to use the interchain account. We will go over the fields of
this message in detail.

### `messages`

This is a list of `CosmosMsg`s that the contract will execute on the counterparty chain using the interchain account.
This execution is atomic. If any of the `CosmosMsg`s fail, then the entire execution will fail.

:::note

All applicable `CosmosMsg`s are supported if the channel was opened with `tx_encoding` set to `proto3`.
However, if the channel was opened with `tx_encoding` set to `proto3json`, then some `CosmosMsg`s are not supported.
Below is a table of the supported `CosmosMsg`s for each `tx_encoding`.

| **CosmosMsg** | `proto3` | `proto3json` |
|:------------------------------------------:|:--------:|:------------:|
| `Stargate` |||
| `BankMsg::Send` |||
| `BankMsg::Burn` |||
| `IbcMsg::Transfer` || 🟢 |
| `IbcMsg::SendPacket` | N/A | N/A |
| `IbcMsg::CloseChannel` | N/A | N/A |
| `WasmMsg::*` |||
| `GovMsg::*` |||
| `StakingMsg::Delegate` |||
| `StakingMsg::*` | 🟢 | 🟢 |
| `DistributionMsg::WithdrawDelegatorReward` | 🟢 | 🟢 |
| `DistributionMsg::*` |||

Note that `🟢` means that the `CosmosMsg` is supported but not tested in the contract's test suite.
These will be tested in the future.

:::

### `packet_memo`

This is the IBC packet memo that will be included in the ICS-27 packet. It is optional and defaults to `""`.
Additionally, the memo field is used by some IBC middleware to execute custom logic on the counterparty chain.
But most of these middlewares do not yet support ICS-27 channels.

### `timeout_seconds`

This is the timeout in seconds that will be used for the ICS-27 packet. It is optional and defaults to [`DEFAULT_TIMEOUT_SECONDS`](https://github.com/srdtrk/cw-ica-controller/blob/v0.5.0/src/ibc/types/packet.rs#L15-L16).

## `SendCustomIcaMessages`

```rust reference
https://github.com/srdtrk/cw-ica-controller/blob/v0.5.0/src/types/msg.rs#L55-L91
```

Recall that the `SendCosmosMsgs` message is the recommended way to use the interchain account. Use this only if you
insist on using `proto3json` encoding and you need to send messages that are not supported by the `SendCosmosMsgs`.

:::note

This message is redundant if the channel was opened with `tx_encoding` set to `proto3`. This is because any custom
message you might want to send will be supported through `CosmosMsg::Stargate`.

:::

I will not go into the details of the fields of this message since it is not recommended to use this message.

## `UpdateCallbackAddress`

```rust reference
https://github.com/srdtrk/cw-ica-controller/blob/v0.5.0/src/types/msg.rs#L92-L97
```

This message is used to update the contract address that this contract will send callbacks to.
This is useful if the owner wants to change the contract that receives the callbacks.
If set to `None`, then no callbacks will be sent.

## `UpdateOwnership`

```rust reference
https://github.com/larry0x/cw-plus-plus/blob/ownable-v0.5.0/packages/ownable/derive/src/lib.rs#L86-L90
```

This message type is provided by the [cw-ownable](https://crates.io/crates/cw-ownable) crate. It wraps a
`cw_ownable::Action` enum.

```rust reference
https://github.com/larry0x/cw-plus-plus/blob/ownable-v0.5.0/packages/ownable/src/lib.rs#L31-L57
```

The owner can propose to transfer the ownership of the contract to a new address using `Action::TransferOwnership` and
set and expiry time for the proposal. If the proposal is accepted before the expiry time through
`Action::AcceptOwnership`, then the ownership of the contract is transferred to the new address.

You can learn more about `cw-ownable` in its crate documentation.
64 changes: 64 additions & 0 deletions docs/versioned_docs/version-v0.5.x/contract-api/03-query-msg.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: QueryMsg
sidebar_label: QueryMsg
sidebar_position: 3
slug: /contract-api/query-msg
---

# `QueryMsg`

The `QueryMsg` is the message that allows you to see the state of the contract. Therefore, it is important to
understand the state of the contract.

## `GetChannel`

```rust reference
https://github.com/srdtrk/cw-ica-controller/blob/v0.5.0/src/types/msg.rs#L105-L107
```

This message is used to query the state of the ICS-27 channel as tracked by the contract. It returns

```rust reference
https://github.com/srdtrk/cw-ica-controller/blob/v0.5.0/src/types/state.rs#L158-L166
```

## `GetContractState`

```rust reference
https://github.com/srdtrk/cw-ica-controller/blob/v0.4.0/src/types/msg.rs#L108-L110
```

This message is used to query the state of the contract. It returns

```rust reference
https://github.com/srdtrk/cw-ica-controller/blob/v0.5.0/src/types/state.rs#L39-L50
```

Lets look at the fields of the `ContractState`:

### `ica_info`

This field will be empty if the channel handshake has not been completed. Otherwise, it will contain the
following information:

```rust reference
https://github.com/srdtrk/cw-ica-controller/blob/v0.5.0/src/types/state.rs#L90-L96
```

### `callback_address`

This is the contract address that the `cw-ica-controller` contract will send callbacks to. If this field is empty,
then the contract will not send callbacks.

## `Ownership`

```rust reference
https://github.com/larry0x/cw-plus-plus/blob/ownable-v0.5.0/packages/ownable/derive/src/lib.rs#L142-L144
```

This message type is provided by the [cw-ownable](https://crates.io/crates/cw-ownable) crate. It allows to query
the ownership of the contract. It returns `Ownership<String>`:

```rust reference
https://github.com/larry0x/cw-plus-plus/blob/ownable-v0.5.0/packages/ownable/src/lib.rs#L14-L29
```
Loading

0 comments on commit c458273

Please sign in to comment.