Skip to content

Commit

Permalink
Merge pull request #6 from hadronlabs-org/feat/LIDO-73-contracts-skel…
Browse files Browse the repository at this point in the history
…eton

feat: LIDO-73. Contracts skeleton
  • Loading branch information
ratik authored Dec 12, 2023
2 parents cb5e350 + d841b18 commit f720f8c
Show file tree
Hide file tree
Showing 26 changed files with 558 additions and 0 deletions.
69 changes: 69 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
[workspace]
members = [
"contracts/distribution",
"contracts/interchain-interceptor",
"contracts/interchain-interceptor-authz",
"contracts/validators-stats",
"contracts/token",
"contracts/validators-set",
"contracts/strategy",
"packages/interchain-interceptor-base"
]

resolver = "2"

[workspace.dependencies]
Expand All @@ -22,6 +26,8 @@ cosmwasm-schema = { version = "1.5.0", default-features = false
cw-storage-plus = { version = "1.2.0", default-features = false }
cw2 = { version = "1.1.2", default-features = false }
cw20 = { version = "1.0.1" }
cosmwasm-storage = { version = "1.5.0" }
cw-multi-test = "0.19.0"
cw-utils = { version = "1.0.3", default-features = false }
schemars = "0.8"
serde = { version = "1.0.127", default-features = false, features = ["derive"] }
Expand Down
2 changes: 2 additions & 0 deletions contracts/distribution/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[alias]
schema = "run --bin lido-distribution-schema"
46 changes: 46 additions & 0 deletions contracts/distribution/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[package]
authors = []
description = "Contract to support staking distribution"
edition = "2021"
name = "lido-distribution"
version = "1.0.0"

exclude = [
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
"contract.wasm",
"hash.txt",
]

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

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

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[dependencies]
cosmos-sdk-proto = { workspace = true }
prost = { workspace = true }
prost-types = { workspace = true }
protobuf = { workspace = true }
tendermint-proto = { workspace = true }

cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw-storage-plus = { workspace = true }
cw-ownable = { workspace = true }
cw2 = { workspace = true }
cw20 = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true }
serde-json-wasm = { workspace = true }

neutron-sdk = { workspace = true }

[dev-dependencies]
cosmwasm-storage = { workspace = true }
cw-multi-test = { workspace = true }
1 change: 1 addition & 0 deletions contracts/distribution/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# LIDO Staking distribution
14 changes: 14 additions & 0 deletions contracts/distribution/src/bin/lido-distribution-schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use cosmwasm_schema::write_api;
use lido_distribution::{
msg::{ExecuteMsg, InstantiateMsg, MigrateMsg},
state::QueryMsg,
};

fn main() {
write_api! {
instantiate: InstantiateMsg,
query: QueryMsg,
execute: ExecuteMsg,
migrate: MigrateMsg
}
}
65 changes: 65 additions & 0 deletions contracts/distribution/src/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use cosmwasm_std::{entry_point, to_json_binary, Deps};
use cosmwasm_std::{Binary, DepsMut, Env, MessageInfo, Response, StdResult};
use cw2::set_contract_version;
use neutron_sdk::bindings::msg::NeutronMsg;
use neutron_sdk::bindings::query::NeutronQuery;
use neutron_sdk::NeutronResult;

use crate::state::{QueryMsg, CONFIG};
use crate::{
msg::{ExecuteMsg, InstantiateMsg, MigrateMsg},
state::Config,
};

const CONTRACT_NAME: &str = concat!("crates.io:lido-validators_stats__", env!("CARGO_PKG_NAME"));
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
_env: Env,
_info: MessageInfo,
msg: InstantiateMsg,
) -> NeutronResult<Response> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

let owner = deps.api.addr_validate(&msg.owner)?;

cw_ownable::initialize_owner(deps.storage, deps.api, Some(&msg.owner))?;

let config = &Config { owner };

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

Ok(Response::default())
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps<NeutronQuery>, env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::Config {} => query_config(deps, env),
}
}

fn query_config(deps: Deps<NeutronQuery>, _env: Env) -> StdResult<Binary> {
let config = CONFIG.load(deps.storage)?;
to_json_binary(&config)
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
_deps: DepsMut<NeutronQuery>,
_env: Env,
_info: MessageInfo,
msg: ExecuteMsg,
) -> NeutronResult<Response<NeutronMsg>> {
match msg {}
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response> {
deps.api.debug("WASMDEBUG: migrate");
Ok(Response::default())
}

// TODO: add tests
3 changes: 3 additions & 0 deletions contracts/distribution/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod contract;
pub mod msg;
pub mod state;
12 changes: 12 additions & 0 deletions contracts/distribution/src/msg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use cosmwasm_schema::cw_serde;

#[cw_serde]
pub struct InstantiateMsg {
pub owner: String,
}

#[cw_serde]
pub enum ExecuteMsg {}

#[cw_serde]
pub struct MigrateMsg {}
18 changes: 18 additions & 0 deletions contracts/distribution/src/state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use cosmwasm_schema::{cw_serde, QueryResponses};

use cosmwasm_std::Addr;
use cw_storage_plus::Item;

#[cw_serde]
pub struct Config {
pub owner: Addr,
}

#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
#[returns(Config)]
Config {},
}

pub const CONFIG: Item<Config> = Item::new("config");
2 changes: 2 additions & 0 deletions contracts/strategy/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[alias]
schema = "run --bin lido-strategy-schema"
46 changes: 46 additions & 0 deletions contracts/strategy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[package]
authors = []
description = "Contract to implement staking strategies"
edition = "2021"
name = "lido-strategy"
version = "1.0.0"

exclude = [
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
"contract.wasm",
"hash.txt",
]

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

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

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[dependencies]
cosmos-sdk-proto = { workspace = true }
prost = { workspace = true }
prost-types = { workspace = true }
protobuf = { workspace = true }
tendermint-proto = { workspace = true }

cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw-storage-plus = { workspace = true }
cw-ownable = { workspace = true }
cw2 = { workspace = true }
cw20 = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true }
serde-json-wasm = { workspace = true }

neutron-sdk = { workspace = true }

[dev-dependencies]
cosmwasm-storage = { workspace = true }
cw-multi-test = { workspace = true }
1 change: 1 addition & 0 deletions contracts/strategy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# LIDO Strategy
14 changes: 14 additions & 0 deletions contracts/strategy/src/bin/lido-strategy-schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use cosmwasm_schema::write_api;
use lido_strategy::{
msg::{ExecuteMsg, InstantiateMsg, MigrateMsg},
state::QueryMsg,
};

fn main() {
write_api! {
instantiate: InstantiateMsg,
query: QueryMsg,
execute: ExecuteMsg,
migrate: MigrateMsg
}
}
Loading

0 comments on commit f720f8c

Please sign in to comment.