Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[feat] Add IBC Hook Contract #19

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/price-feed/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ fn query_reference_data_bulk(
.map(|pair| query_reference_data(deps, pair))
.collect()
}

// TODO: Writing test
#[cfg(test)]
mod tests {}
41 changes: 41 additions & 0 deletions contracts/tunnel-consumer-ibc-hook/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[package]
name = "tunnel-consumer-ibc-hook"
version = "0.1.0"
authors = ["Band Protocol <connect@bandprotocol.com>"]
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib", "rlib"]

[profile.release]
opt-level = 3
debug = false
rpath = false
lto = true
debug-assertions = false
codegen-units = 1
panic = 'abort'
incremental = false
overflow-checks = true

[features]
# use library feature to disable all instantiate/execute/query exports
library = []

[package.metadata.scripts]
optimize = """docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/optimizer:0.15.0
"""

[dependencies]
cosmwasm-schema = "2.1.0"
cosmwasm-std = "2.1.4"
cw-band = { path = "../../packages/cw-band", version = "0.3.0", features = ["tunnel"] }
cw-storage-plus = "2.0.0"
cw-controllers = "2.0.0"
cw2 = "2.0.0"
thiserror = { version = "1.0.58" }
85 changes: 85 additions & 0 deletions contracts/tunnel-consumer-ibc-hook/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# CosmWasm Starter Pack

This is a template to build smart contracts in Rust to run inside a
[Cosmos SDK](https://github.com/cosmos/cosmos-sdk) module on all chains that enable it.
To understand the framework better, please read the overview in the
[cosmwasm repo](https://github.com/CosmWasm/cosmwasm/blob/master/README.md),
and dig into the [cosmwasm docs](https://www.cosmwasm.com).
This assumes you understand the theory and just want to get coding.

## Creating a new repo from template

Assuming you have a recent version of Rust and Cargo installed
(via [rustup](https://rustup.rs/)),
then the following should get you a new repo to start a contract:

Install [cargo-generate](https://github.com/ashleygwilliams/cargo-generate) and cargo-run-script.
Unless you did that before, run this line now:

```sh
cargo install cargo-generate --features vendored-openssl
cargo install cargo-run-script
```

Now, use it to create your new contract.
Go to the folder in which you want to place it and run:

**Latest**

```sh
cargo generate --git https://github.com/CosmWasm/cw-template.git --name PROJECT_NAME
```

For cloning minimal code repo:

```sh
cargo generate --git https://github.com/CosmWasm/cw-template.git --name PROJECT_NAME -d minimal=true
```

You will now have a new folder called `PROJECT_NAME` (I hope you changed that to something else)
containing a simple working contract and build system that you can customize.

## Create a Repo

After generating, you have a initialized local git repo, but no commits, and no remote.
Go to a server (eg. github) and create a new upstream repo (called `YOUR-GIT-URL` below).
Then run the following:

```sh
# this is needed to create a valid Cargo.lock file (see below)
cargo check
git branch -M main
git add .
git commit -m 'Initial Commit'
git remote add origin YOUR-GIT-URL
git push -u origin main
```

## CI Support

We have template configurations for both [GitHub Actions](.github/workflows/Basic.yml)
and [Circle CI](.circleci/config.yml) in the generated project, so you can
get up and running with CI right away.

One note is that the CI runs all `cargo` commands
with `--locked` to ensure it uses the exact same versions as you have locally. This also means
you must have an up-to-date `Cargo.lock` file, which is not auto-generated.
The first time you set up the project (or after adding any dep), you should ensure the
`Cargo.lock` file is updated, so the CI will test properly. This can be done simply by
running `cargo check` or `cargo unit-test`.

## Using your project

Once you have your custom repo, you should check out [Developing](./Developing.md) to explain
more on how to run tests and develop code. Or go through the
[online tutorial](https://docs.cosmwasm.com/) to get a better feel
of how to develop.

[Publishing](./Publishing.md) contains useful information on how to publish your contract
to the world, once you are ready to deploy it on a running blockchain. And
[Importing](./Importing.md) contains information about pulling in other contracts or crates
that have been published.

Please replace this README file with information about your specific project. You can keep
the `Developing.md` and `Publishing.md` files as useful references, but please set some
proper description in the README.
174 changes: 174 additions & 0 deletions contracts/tunnel-consumer-ibc-hook/schema/raw/execute.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ExecuteMsg",
"oneOf": [
{
"type": "object",
"required": [
"receive_packet"
],
"properties": {
"receive_packet": {
"type": "object",
"required": [
"packet"
],
"properties": {
"packet": {
"$ref": "#/definitions/TunnelPacket"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"add_senders"
],
"properties": {
"add_senders": {
"type": "object",
"required": [
"msg"
],
"properties": {
"msg": {
"$ref": "#/definitions/AddSendersMsg"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"remove_senders"
],
"properties": {
"remove_senders": {
"type": "object",
"required": [
"msg"
],
"properties": {
"msg": {
"$ref": "#/definitions/RemoveSendersMsg"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
],
"definitions": {
"AddSendersMsg": {
"type": "object",
"required": [
"senders"
],
"properties": {
"senders": {
"type": "array",
"items": {
"$ref": "#/definitions/Addr"
}
}
},
"additionalProperties": false
},
"Addr": {
"description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.",
"type": "string"
},
"Int64": {
"description": "An implementation of i64 that is using strings for JSON encoding/decoding, such that the full i64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `i64` to get the value out:\n\n``` # use cosmwasm_std::Int64; let a = Int64::from(258i64); assert_eq!(a.i64(), 258); ```",
"type": "string"
},
"Price": {
"type": "object",
"required": [
"price",
"signal_id",
"status",
"timestamp"
],
"properties": {
"price": {
"$ref": "#/definitions/Uint64"
},
"signal_id": {
"type": "string"
},
"status": {
"$ref": "#/definitions/Status"
},
"timestamp": {
"$ref": "#/definitions/Int64"
}
},
"additionalProperties": false
},
"RemoveSendersMsg": {
"type": "object",
"required": [
"senders"
],
"properties": {
"senders": {
"type": "array",
"items": {
"$ref": "#/definitions/Addr"
}
}
},
"additionalProperties": false
},
"Status": {
"type": "string",
"enum": [
"PRICE_STATUS_UNSPECIFIED",
"PRICE_STATUS_UNKNOWN_SIGNAL_ID",
"PRICE_STATUS_NOT_READY",
"PRICE_STATUS_AVAILABLE",
"PRICE_STATUS_NOT_IN_CURRENT_FEEDS"
]
},
"TunnelPacket": {
"type": "object",
"required": [
"created_at",
"prices",
"sequence",
"tunnel_id"
],
"properties": {
"created_at": {
"$ref": "#/definitions/Int64"
},
"prices": {
"type": "array",
"items": {
"$ref": "#/definitions/Price"
}
},
"sequence": {
"$ref": "#/definitions/Uint64"
},
"tunnel_id": {
"$ref": "#/definitions/Uint64"
}
},
"additionalProperties": false
},
"Uint64": {
"description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```",
"type": "string"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "InstantiateMsg",
"type": "object",
"additionalProperties": false
}
30 changes: 30 additions & 0 deletions contracts/tunnel-consumer-ibc-hook/schema/raw/query.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "QueryMsg",
"oneOf": [
{
"type": "object",
"required": [
"prices"
],
"properties": {
"prices": {
"type": "object",
"required": [
"signal_ids"
],
"properties": {
"signal_ids": {
"type": "array",
"items": {
"type": "string"
}
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
]
}
Loading