From 56981a79e726b621c5be2d367bdb113f5c573e3d Mon Sep 17 00:00:00 2001 From: brimigs <85972460+brimigs@users.noreply.github.com> Date: Mon, 6 Feb 2023 16:53:54 -0500 Subject: [PATCH] update readme (#13) * 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 <26318510+larry0x@users.noreply.github.com> Co-authored-by: Piotr Babel --- Cargo.lock | 26 ++-- Cargo.toml | 13 +- README.md | 129 ++++++++++++++---- contracts/liquidation-filterer/Cargo.toml | 1 + .../liquidation-filterer/src/contract.rs | 11 +- .../mars-liquidation-filterer.json | 2 +- scripts/deploy/addresses/osmo-test-4.json | 2 +- scripts/deploy/base/deployer.ts | 10 +- scripts/deploy/base/index.ts | 2 +- scripts/deploy/osmosis/config.ts | 20 +-- scripts/deploy/osmosis/testIndex.ts | 6 + scripts/types/config.ts | 6 - scripts/types/storageItems.ts | 8 +- 13 files changed, 144 insertions(+), 92 deletions(-) create mode 100644 scripts/deploy/osmosis/testIndex.ts diff --git a/Cargo.lock b/Cargo.lock index b7c2e40..b0ab474 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -483,7 +483,7 @@ checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "mars-address-provider" version = "1.0.0" -source = "git+https://github.com/mars-protocol/red-bank?rev=3e57365#3e57365d82b96967ef1bc7ec183c4a86bc88d5e7" +source = "git+https://github.com/mars-protocol/red-bank?rev=13fcc44#13fcc446fe687dfb8f08ffacd57b1ab6ad6cfcc9" dependencies = [ "bech32", "cosmwasm-std", @@ -497,7 +497,7 @@ dependencies = [ [[package]] name = "mars-health" version = "1.0.0" -source = "git+https://github.com/mars-protocol/red-bank?rev=3e57365#3e57365d82b96967ef1bc7ec183c4a86bc88d5e7" +source = "git+https://github.com/mars-protocol/red-bank?rev=13fcc44#13fcc446fe687dfb8f08ffacd57b1ab6ad6cfcc9" dependencies = [ "cosmwasm-std", "mars-red-bank-types", @@ -507,7 +507,7 @@ dependencies = [ [[package]] name = "mars-incentives" version = "1.0.0" -source = "git+https://github.com/mars-protocol/red-bank?rev=3e57365#3e57365d82b96967ef1bc7ec183c4a86bc88d5e7" +source = "git+https://github.com/mars-protocol/red-bank?rev=13fcc44#13fcc446fe687dfb8f08ffacd57b1ab6ad6cfcc9" dependencies = [ "cosmwasm-std", "cw-storage-plus", @@ -520,7 +520,7 @@ dependencies = [ [[package]] name = "mars-liquidation-filterer" -version = "0.1.0" +version = "1.0.0" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -537,7 +537,7 @@ dependencies = [ [[package]] name = "mars-oracle-base" version = "1.0.0" -source = "git+https://github.com/mars-protocol/red-bank?rev=3e57365#3e57365d82b96967ef1bc7ec183c4a86bc88d5e7" +source = "git+https://github.com/mars-protocol/red-bank?rev=13fcc44#13fcc446fe687dfb8f08ffacd57b1ab6ad6cfcc9" dependencies = [ "cosmwasm-std", "cw-storage-plus", @@ -552,7 +552,7 @@ dependencies = [ [[package]] name = "mars-oracle-osmosis" version = "1.0.0" -source = "git+https://github.com/mars-protocol/red-bank?rev=3e57365#3e57365d82b96967ef1bc7ec183c4a86bc88d5e7" +source = "git+https://github.com/mars-protocol/red-bank?rev=13fcc44#13fcc446fe687dfb8f08ffacd57b1ab6ad6cfcc9" dependencies = [ "cosmwasm-std", "cw-storage-plus", @@ -569,7 +569,7 @@ dependencies = [ [[package]] name = "mars-osmosis" version = "1.0.0" -source = "git+https://github.com/mars-protocol/red-bank?rev=3e57365#3e57365d82b96967ef1bc7ec183c4a86bc88d5e7" +source = "git+https://github.com/mars-protocol/red-bank?rev=13fcc44#13fcc446fe687dfb8f08ffacd57b1ab6ad6cfcc9" dependencies = [ "cosmwasm-std", "osmosis-std", @@ -592,7 +592,7 @@ dependencies = [ [[package]] name = "mars-red-bank" version = "1.0.0" -source = "git+https://github.com/mars-protocol/red-bank?rev=3e57365#3e57365d82b96967ef1bc7ec183c4a86bc88d5e7" +source = "git+https://github.com/mars-protocol/red-bank?rev=13fcc44#13fcc446fe687dfb8f08ffacd57b1ab6ad6cfcc9" dependencies = [ "cosmwasm-std", "cw-storage-plus", @@ -608,7 +608,7 @@ dependencies = [ [[package]] name = "mars-red-bank-types" version = "1.0.0" -source = "git+https://github.com/mars-protocol/red-bank?rev=3e57365#3e57365d82b96967ef1bc7ec183c4a86bc88d5e7" +source = "git+https://github.com/mars-protocol/red-bank?rev=13fcc44#13fcc446fe687dfb8f08ffacd57b1ab6ad6cfcc9" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -620,7 +620,7 @@ dependencies = [ [[package]] name = "mars-rewards-collector-base" version = "1.0.0" -source = "git+https://github.com/mars-protocol/red-bank?rev=3e57365#3e57365d82b96967ef1bc7ec183c4a86bc88d5e7" +source = "git+https://github.com/mars-protocol/red-bank?rev=13fcc44#13fcc446fe687dfb8f08ffacd57b1ab6ad6cfcc9" dependencies = [ "cosmwasm-std", "cw-storage-plus", @@ -635,7 +635,7 @@ dependencies = [ [[package]] name = "mars-rewards-collector-osmosis" version = "1.0.0" -source = "git+https://github.com/mars-protocol/red-bank?rev=3e57365#3e57365d82b96967ef1bc7ec183c4a86bc88d5e7" +source = "git+https://github.com/mars-protocol/red-bank?rev=13fcc44#13fcc446fe687dfb8f08ffacd57b1ab6ad6cfcc9" dependencies = [ "cosmwasm-std", "cw-storage-plus", @@ -652,7 +652,7 @@ dependencies = [ [[package]] name = "mars-testing" version = "1.0.0" -source = "git+https://github.com/mars-protocol/red-bank?rev=3e57365#3e57365d82b96967ef1bc7ec183c4a86bc88d5e7" +source = "git+https://github.com/mars-protocol/red-bank?rev=13fcc44#13fcc446fe687dfb8f08ffacd57b1ab6ad6cfcc9" dependencies = [ "anyhow", "cosmwasm-std", @@ -674,7 +674,7 @@ dependencies = [ [[package]] name = "mars-utils" version = "1.0.0" -source = "git+https://github.com/mars-protocol/red-bank?rev=3e57365#3e57365d82b96967ef1bc7ec183c4a86bc88d5e7" +source = "git+https://github.com/mars-protocol/red-bank?rev=13fcc44#13fcc446fe687dfb8f08ffacd57b1ab6ad6cfcc9" dependencies = [ "cosmwasm-std", "thiserror", diff --git a/Cargo.toml b/Cargo.toml index 58d1e84..cc6efc0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,12 +2,13 @@ members = ["contracts/*"] [workspace.package] -version = "0.1.0" +version = "1.0.0" authors = [ "Piotr Babel ", "Larry Engineer ", ] 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/" @@ -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" diff --git a/README.md b/README.md index 2be7549..21ebde9 100644 --- a/README.md +++ b/README.md @@ -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 + 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 diff --git a/contracts/liquidation-filterer/Cargo.toml b/contracts/liquidation-filterer/Cargo.toml index ae21563..2be6c0d 100644 --- a/contracts/liquidation-filterer/Cargo.toml +++ b/contracts/liquidation-filterer/Cargo.toml @@ -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 } diff --git a/contracts/liquidation-filterer/src/contract.rs b/contracts/liquidation-filterer/src/contract.rs index 217897e..1190242 100644 --- a/contracts/liquidation-filterer/src/contract.rs +++ b/contracts/liquidation-filterer/src/contract.rs @@ -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) } @@ -107,7 +106,7 @@ fn execute_liquidate( ) -> Result { 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, @@ -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); @@ -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)) } @@ -208,7 +207,7 @@ fn to_red_bank_liquidate_msg( #[entry_point] pub fn reply(_deps: DepsMut, _env: Env, reply: Reply) -> StdResult { 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()); diff --git a/schemas/mars-liquidation-filterer/mars-liquidation-filterer.json b/schemas/mars-liquidation-filterer/mars-liquidation-filterer.json index a067376..ed5b1bc 100644 --- a/schemas/mars-liquidation-filterer/mars-liquidation-filterer.json +++ b/schemas/mars-liquidation-filterer/mars-liquidation-filterer.json @@ -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#", diff --git a/scripts/deploy/addresses/osmo-test-4.json b/scripts/deploy/addresses/osmo-test-4.json index bff9337..126655d 100644 --- a/scripts/deploy/addresses/osmo-test-4.json +++ b/scripts/deploy/addresses/osmo-test-4.json @@ -1 +1 @@ -{ "liquidationFilterer": "osmo15p9fjektet5pcqp6g7kcxg9yqgh973n8gmmnq6ltf8txs4fucvsqwljxy0" } +{ "liquidation-filterer": "osmo1lnjyeyr5vtnsj4sv9guv7z322kmeytt3curm9u840yg2y2hk5w6qsdjjzu" } diff --git a/scripts/deploy/base/deployer.ts b/scripts/deploy/base/deployer.ts index 2e18493..13b5e01 100644 --- a/scripts/deploy/base/deployer.ts +++ b/scripts/deploy/base/deployer.ts @@ -77,7 +77,11 @@ export class Deployer { owner: this.deployerAddress, address_provider: this.addresses.addressProvider, } - await this.instantiate('liquidationFilterer', this.storage.codeIds.liquidationFilterer!, msg) + await this.instantiate( + 'liquidation-filterer', + this.storage.codeIds['liquidation-filterer']!, + msg, + ) } async saveDeploymentAddrsToFile() { @@ -98,13 +102,13 @@ export class Deployer { } await this.client.execute( this.deployerAddress, - this.storage.addresses.liquidationFilterer!, + this.storage.addresses['liquidation-filterer']!, msg, 'auto', ) printYellow('Owner updated to Mutlisig for Liquidation Filterer') const filtererConfig = (await this.client.queryContractSmart( - this.storage.addresses.liquidationFilterer!, + this.storage.addresses['liquidation-filterer']!, { config: {}, }, diff --git a/scripts/deploy/base/index.ts b/scripts/deploy/base/index.ts index 671a9c1..0ef41e9 100644 --- a/scripts/deploy/base/index.ts +++ b/scripts/deploy/base/index.ts @@ -9,7 +9,7 @@ export const taskRunner = async (config: DeploymentConfig, address: Addresses) = await deployer.assertDeployerBalance() // Upload contracts - await deployer.upload('liquidationFilterer', 'mars_liquidation_filterer.wasm') + await deployer.upload('liquidation-filterer', 'mars_liquidation_filterer.wasm') // Instantiate contracts await deployer.instantiateLiquidationFilterer() diff --git a/scripts/deploy/osmosis/config.ts b/scripts/deploy/osmosis/config.ts index cb1d39b..f8a3b3a 100644 --- a/scripts/deploy/osmosis/config.ts +++ b/scripts/deploy/osmosis/config.ts @@ -2,52 +2,34 @@ import { DeploymentConfig, Addresses } from '../../types/config' export const osmosisTestnetConfig: DeploymentConfig = { chainName: 'osmosis', - atomDenom: 'ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2', baseAssetDenom: 'uosmo', chainId: 'osmo-test-4', chainPrefix: 'osmo', rpcEndpoint: 'https://rpc-test.osmosis.zone', - safetyFundFeeShare: '0.2', - timeoutRevision: 1, deployerMnemonic: 'elevator august inherit simple buddy giggle zone despair marine rich swim danger blur people hundred faint ladder wet toe strong blade utility trial process', - slippage_tolerance: '0.5', - base_asset_symbol: 'OSMO', - second_asset_symbol: 'ATOM', } export const osmosisLocalConfig: DeploymentConfig = { chainName: 'osmosis', - atomDenom: 'ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2', baseAssetDenom: 'uosmo', chainId: 'localosmosis', chainPrefix: 'osmo', rpcEndpoint: 'http://localhost:26657', - safetyFundFeeShare: '0.2', - timeoutRevision: 1, deployerMnemonic: 'notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius', - slippage_tolerance: '0.5', - base_asset_symbol: 'OSMO', - second_asset_symbol: 'ATOM', } export const osmosisMainnet: DeploymentConfig = { chainName: 'osmosis', - atomDenom: 'ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2', baseAssetDenom: 'uosmo', chainId: 'osmosis-1', chainPrefix: 'osmo', rpcEndpoint: 'https://rpc.osmosis.zone', - safetyFundFeeShare: '0.2', - timeoutRevision: 1, deployerMnemonic: 'TO BE INSERTED AT TIME OF DEPLOYMENT', - slippage_tolerance: '0.1', - base_asset_symbol: 'OSMO', - second_asset_symbol: 'ATOM', } export const osmosisTestnetAddresses: Addresses = { multisig: 'osmo14w4x949nwcrqgfe53pxs3k7x53p0gvlrq34l5n', - addressProvider: 'osmo1cnsrp4aj2wq8gx0eyelc4r8aj0m6s9mct6gdhxwlaymaczfayvyq9rxrm2', + addressProvider: 'osmo17dyy6hyzzy6u5khy5lau7afa2y9kwknu0aprwqn8twndw2qhv8ls6msnjr', } // FIXME: Add in mainnet addr provider addr before deployment diff --git a/scripts/deploy/osmosis/testIndex.ts b/scripts/deploy/osmosis/testIndex.ts new file mode 100644 index 0000000..08eabb3 --- /dev/null +++ b/scripts/deploy/osmosis/testIndex.ts @@ -0,0 +1,6 @@ +import { taskRunner } from '../base' +import { osmosisTestnetAddresses, osmosisTestnetConfig } from './config.js' + +void (async function () { + await taskRunner(osmosisTestnetConfig, osmosisTestnetAddresses) +})() diff --git a/scripts/types/config.ts b/scripts/types/config.ts index e208f3d..62ca68c 100644 --- a/scripts/types/config.ts +++ b/scripts/types/config.ts @@ -1,16 +1,10 @@ export interface DeploymentConfig { chainName: string baseAssetDenom: string - atomDenom: string chainPrefix: string - safetyFundFeeShare: string - timeoutRevision: number chainId: string rpcEndpoint: string deployerMnemonic: string - slippage_tolerance: string - base_asset_symbol: string - second_asset_symbol: string } export interface Addresses { diff --git a/scripts/types/storageItems.ts b/scripts/types/storageItems.ts index e77202d..6580afd 100644 --- a/scripts/types/storageItems.ts +++ b/scripts/types/storageItems.ts @@ -1,11 +1,11 @@ export interface StorageItems { codeIds: { - liquidationFilterer?: number - addressProvider?: number + 'liquidation-filterer'?: number + 'address-provider'?: number } addresses: { - liquidationFilterer?: string - addressProvider?: string + 'liquidation-filterer'?: string + 'address-provider'?: string } execute: { addressProviderUpdated?: boolean