Skip to content

Commit

Permalink
update readme (#13)
Browse files Browse the repository at this point in the history
* update readme

* minor formatting

* fix (#12)

* Update Cargo files.

* Make action value consistent with guideline.

* Update schema.

* Update scripts and readme.

---------

Co-authored-by: Larry Engineer <[email protected]>
Co-authored-by: Piotr Babel <[email protected]>
  • Loading branch information
3 people authored Feb 6, 2023
1 parent a8f941e commit 56981a7
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 92 deletions.
26 changes: 13 additions & 13 deletions Cargo.lock

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

13 changes: 5 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
members = ["contracts/*"]

[workspace.package]
version = "0.1.0"
version = "1.0.0"
authors = [
"Piotr Babel <[email protected]>",
"Larry Engineer <[email protected]>",
]
edition = "2021"
license = "GPL-3.0-or-later"
repository = "https://github.com/mars-protocol/liquidation-helpers"
homepage = "https://marsprotocol.io"
documentation = "https://docs.marsprotocol.io/"
Expand All @@ -18,14 +19,10 @@ cosmwasm-schema = "1.2.1"
cosmwasm-std = "1.2.1"
cw2 = "1.0.1"
cw-storage-plus = "1.0.1"
cw-utils = "1.0.1"
mars-osmosis = { version = "1.0.0", git = "https://github.com/mars-protocol/red-bank", rev = "3e57365" }
mars-owner = "1.0.0"
# FIXME: update these once they're published to crates.io
mars-red-bank-types = { version = "1.0.0", git = "https://github.com/mars-protocol/red-bank", rev = "3e57365" }
mars-testing = { version = "1.0.0", git = "https://github.com/mars-protocol/red-bank", rev = "3e57365" }
mars-utils = { version = "1.0.0", git = "https://github.com/mars-protocol/red-bank", rev = "3e57365" }
osmosis-std = "0.14.0"
mars-red-bank-types = { version = "1.0.0", git = "https://github.com/mars-protocol/red-bank", rev = "13fcc44" }
mars-testing = { version = "1.0.0", git = "https://github.com/mars-protocol/red-bank", rev = "13fcc44" }
mars-utils = { version = "1.0.0", git = "https://github.com/mars-protocol/red-bank", rev = "13fcc44" }
schemars = "0.8.11"
serde = { version = "1.0.152", default-features = false, features = ["derive"] }
thiserror = "1.0.38"
Expand Down
129 changes: 99 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,129 @@

Helpers smart contracts

## Deploy scripts set up
## Verify contracts

Everything related to deployment must be ran from the `scripts` directory:
### For contracts deployed on the Osmosis chain

```bash
cd scripts
```
1. Install [Osmosisd][1]

Set up yarn:
2. Get the wasm binary executable on your local machine.

```bash
yarn install
```
```bash
git clone https://github.com/mars-protocol/liquidaiton-helpers.git
git checkout <commit-id>
cargo make rust-optimizer
```

Create the build folder:
Note: Intel/Amd 64-bit processor is required. While there is experimental ARM support for CosmWasm/rust-optimizer, it's discouraged to use in production and the wasm bytecode will not match up to an Intel compiled wasm file.

```bash
yarn build
```
3. Download the wasm from the chain.

Compile all contracts:
```bash
osmosisd query wasm code $CODEID -- $NODE download.wasm
```

```bash
yarn compile
```
4. Verify that the diff is empty between them. If any value is returned, then the wasm files differ.

This compiles and optimizes all contracts, storing them in `/artifacts` directory along with `checksum.txt` which contains sha256 hashes of each of the `.wasm` files (The script just uses CosmWasm's [rust-optimizer](https://github.com/CosmWasm/rust-optimizer)).
```bash
diff artifacts/$CONTRACTNAME.wasm download.wasm
```

Note: Docker deamon must be running to run this command.
5. Alternatively, compare the wasm files' checksums:
Formating must be done before running lint:
```bash
sha256sum artifacts/$CONTRACTNAME.wasm download.wasm
```
```bash
yarn format
```
## Environment set up
- Install [rustup][2]. Once installed, make sure you have the wasm32 target:
```bash
rustup default stable
rustup update stable
rustup target add wasm32-unknown-unknown
```
- Install [cargo-make][3]
```bash
cargo install --force cargo-make
```
- Install [Docker][4]
- Install [Node.js v16][5]
Linting:
- Install [Yarn][6]
- Create the build folder:
```bash
yarn build
```
- Compile all contracts:
```bash
cargo make rust-optimizer
```
- Formatting:
```bash
yarn format
yarn lint
```
This compiles and optimizes all contracts, storing them in `/artifacts` directory along with `checksum.txt` which contains sha256 hashes of each of the `.wasm` files (The script just uses CosmWasm's [rust-optimizer][7]).

**Note:** Intel/Amd 64-bit processor is required. While there is experimental ARM support for CosmWasm/rust-optimizer, it's discouraged to use in production.

## Schemas

```bash
yarn lint
cargo make --makefile Makefile.toml generate-all-schemas
```

Now you're ready to deploy for an outpost.
Creates JSON schema files for relevant contract calls, queries and query responses (See: [cosmwams-schema][8]).

## Deploying to an Outpost
## Deployment

Each outpost has a config file for its respective deployment and assets
Everything related to deployment must be ran from the `scripts` directory:

For Osmosis:
For the Osmosis Outpost:

```bash
yarn deploy:osmosis
cd scripts
# for testnet deployment:
yarn deploy:osmosis-testnet
# for mainnet deployment:
yarn deploy:osmosis-mainnet
```

## Deployments

### osmosis-1

TBD

### osmo-test-4

| Contract | Address |
|----------------------| ----------------------------------------------------------------- |
| liquidation-filterer | `osmo1lnjyeyr5vtnsj4sv9guv7z322kmeytt3curm9u840yg2y2hk5w6qsdjjzu` |

## License

Contents of this repository are open source under [GNU General Public License v3](./LICENSE) or later.

[1]: https://docs.osmosis.zone/osmosis-core/osmosisd/
[2]: https://rustup.rs/
[3]: https://github.com/sagiegurari/cargo-make
[4]: https://docs.docker.com/get-docker/
[5]: https://github.com/nvm-sh/nvm
[6]: https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable
[7]: https://github.com/CosmWasm/rust-optimizer
[8]: https://github.com/CosmWasm/cosmwasm/tree/main/packages/schema
1 change: 1 addition & 0 deletions contracts/liquidation-filterer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "mars-liquidation-filterer"
version = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
documentation = { workspace = true }
Expand Down
11 changes: 5 additions & 6 deletions contracts/liquidation-filterer/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ fn execute_update_config(

CONFIG.save(deps.storage, &config)?;

let response =
Response::new().add_attribute("action", "periphery/liquidation-filterer/update_config");
let response = Response::new().add_attribute("action", "update_config");

Ok(response)
}
Expand All @@ -107,7 +106,7 @@ fn execute_liquidate(
) -> Result<Response, ContractError> {
let config = CONFIG.load(deps.storage)?;

let red_bank_addr = address_provider::helpers::query_address(
let red_bank_addr = address_provider::helpers::query_contract_addr(
deps.as_ref(),
&config.address_provider,
MarsAddressType::RedBank,
Expand Down Expand Up @@ -153,7 +152,7 @@ fn execute_liquidate(
};

let response = Response::new()
.add_attributes(vec![attr("action", "periphery/liquidation-filterer/liquidate_many")])
.add_attributes(vec![attr("action", "liquidate_many")])
.add_submessages(submsgs)
.add_message(refund_msg);

Expand Down Expand Up @@ -184,7 +183,7 @@ fn execute_refund(
to_address: recipient.to_string(),
amount: coins,
})
.add_attribute("action", "periphery/liquidation-filterer/refund")
.add_attribute("action", "refund")
.add_attribute("recipient", recipient)
.add_attribute("coins", coins_str))
}
Expand All @@ -208,7 +207,7 @@ fn to_red_bank_liquidate_msg(
#[entry_point]
pub fn reply(_deps: DepsMut, _env: Env, reply: Reply) -> StdResult<Response> {
let res = Response::new()
.add_attribute("action", "periphery/liquidation-filterer/handle_reply")
.add_attribute("action", "handle_reply")
.add_attribute("id", reply.id.to_string())
.add_attribute("success", reply.result.is_ok().to_string());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "mars-liquidation-filterer",
"contract_version": "0.1.0",
"contract_version": "1.0.0",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy/addresses/osmo-test-4.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "liquidationFilterer": "osmo15p9fjektet5pcqp6g7kcxg9yqgh973n8gmmnq6ltf8txs4fucvsqwljxy0" }
{ "liquidation-filterer": "osmo1lnjyeyr5vtnsj4sv9guv7z322kmeytt3curm9u840yg2y2hk5w6qsdjjzu" }
Loading

0 comments on commit 56981a7

Please sign in to comment.