diff --git a/smart-contracts/osmosis/Cargo.lock b/smart-contracts/osmosis/Cargo.lock index 2816a2f67..92bb9a5b9 100644 --- a/smart-contracts/osmosis/Cargo.lock +++ b/smart-contracts/osmosis/Cargo.lock @@ -1406,6 +1406,7 @@ dependencies = [ "cosmwasm-std", "cw-storage-plus 1.2.0", "cw2 1.1.2", + "mars-owner", "thiserror", ] diff --git a/smart-contracts/quasar/contracts/babylon-vault/Cargo.toml b/smart-contracts/quasar/contracts/babylon-vault/Cargo.toml index 11290aad4..02b1b7e7a 100644 --- a/smart-contracts/quasar/contracts/babylon-vault/Cargo.toml +++ b/smart-contracts/quasar/contracts/babylon-vault/Cargo.toml @@ -29,3 +29,4 @@ cosmwasm-schema = { workspace = true } cw-storage-plus = { workspace = true } thiserror = { workspace = true } cw2 = { workspace = true } +mars-owner = { workspace = true } diff --git a/smart-contracts/quasar/contracts/babylon-vault/schema/babylon-vault.json b/smart-contracts/quasar/contracts/babylon-vault/schema/babylon-vault.json index cb0a68945..bf5028774 100644 --- a/smart-contracts/quasar/contracts/babylon-vault/schema/babylon-vault.json +++ b/smart-contracts/quasar/contracts/babylon-vault/schema/babylon-vault.json @@ -6,6 +6,14 @@ "$schema": "http://json-schema.org/draft-07/schema#", "title": "InstantiateMsg", "type": "object", + "required": [ + "owner" + ], + "properties": { + "owner": { + "type": "string" + } + }, "additionalProperties": false }, "execute": { @@ -71,8 +79,69 @@ } }, "additionalProperties": false + }, + { + "type": "object", + "required": [ + "update_owner" + ], + "properties": { + "update_owner": { + "$ref": "#/definitions/OwnerUpdate" + } + }, + "additionalProperties": false } - ] + ], + "definitions": { + "OwnerUpdate": { + "oneOf": [ + { + "description": "Proposes a new owner to take role. Only current owner can execute.", + "type": "object", + "required": [ + "propose_new_owner" + ], + "properties": { + "propose_new_owner": { + "type": "object", + "required": [ + "proposed" + ], + "properties": { + "proposed": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Clears the currently proposed owner. Only current owner can execute.", + "type": "string", + "enum": [ + "clear_proposed" + ] + }, + { + "description": "Promotes the proposed owner to be the current one. Only the proposed owner can execute.", + "type": "string", + "enum": [ + "accept_proposed" + ] + }, + { + "description": "Throws away the keys to the Owner role forever. Once done, no owner can ever be set later.", + "type": "string", + "enum": [ + "abolish_owner_role" + ] + } + ] + } + } }, "query": { "$schema": "http://json-schema.org/draft-07/schema#", @@ -132,6 +201,19 @@ } }, "additionalProperties": false + }, + { + "type": "object", + "required": [ + "owner" + ], + "properties": { + "owner": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false } ] }, @@ -150,6 +232,37 @@ "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 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 `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", "type": "string" }, + "owner": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "OwnerResponse", + "description": "Returned from Owner.query()", + "type": "object", + "required": [ + "abolished", + "initialized" + ], + "properties": { + "abolished": { + "type": "boolean" + }, + "initialized": { + "type": "boolean" + }, + "owner": { + "type": [ + "string", + "null" + ] + }, + "proposed": { + "type": [ + "string", + "null" + ] + } + }, + "additionalProperties": false + }, "pending": { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Array_of_Claim", diff --git a/smart-contracts/quasar/contracts/babylon-vault/schema/raw/execute.json b/smart-contracts/quasar/contracts/babylon-vault/schema/raw/execute.json index b978c2b19..ee6d7301a 100644 --- a/smart-contracts/quasar/contracts/babylon-vault/schema/raw/execute.json +++ b/smart-contracts/quasar/contracts/babylon-vault/schema/raw/execute.json @@ -61,6 +61,67 @@ } }, "additionalProperties": false + }, + { + "type": "object", + "required": [ + "update_owner" + ], + "properties": { + "update_owner": { + "$ref": "#/definitions/OwnerUpdate" + } + }, + "additionalProperties": false + } + ], + "definitions": { + "OwnerUpdate": { + "oneOf": [ + { + "description": "Proposes a new owner to take role. Only current owner can execute.", + "type": "object", + "required": [ + "propose_new_owner" + ], + "properties": { + "propose_new_owner": { + "type": "object", + "required": [ + "proposed" + ], + "properties": { + "proposed": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "description": "Clears the currently proposed owner. Only current owner can execute.", + "type": "string", + "enum": [ + "clear_proposed" + ] + }, + { + "description": "Promotes the proposed owner to be the current one. Only the proposed owner can execute.", + "type": "string", + "enum": [ + "accept_proposed" + ] + }, + { + "description": "Throws away the keys to the Owner role forever. Once done, no owner can ever be set later.", + "type": "string", + "enum": [ + "abolish_owner_role" + ] + } + ] } - ] + } } diff --git a/smart-contracts/quasar/contracts/babylon-vault/schema/raw/instantiate.json b/smart-contracts/quasar/contracts/babylon-vault/schema/raw/instantiate.json index 1352613d5..66e351258 100644 --- a/smart-contracts/quasar/contracts/babylon-vault/schema/raw/instantiate.json +++ b/smart-contracts/quasar/contracts/babylon-vault/schema/raw/instantiate.json @@ -2,5 +2,13 @@ "$schema": "http://json-schema.org/draft-07/schema#", "title": "InstantiateMsg", "type": "object", + "required": [ + "owner" + ], + "properties": { + "owner": { + "type": "string" + } + }, "additionalProperties": false } diff --git a/smart-contracts/quasar/contracts/babylon-vault/schema/raw/query.json b/smart-contracts/quasar/contracts/babylon-vault/schema/raw/query.json index 630717c77..65de6f167 100644 --- a/smart-contracts/quasar/contracts/babylon-vault/schema/raw/query.json +++ b/smart-contracts/quasar/contracts/babylon-vault/schema/raw/query.json @@ -56,6 +56,19 @@ } }, "additionalProperties": false + }, + { + "type": "object", + "required": [ + "owner" + ], + "properties": { + "owner": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false } ] } diff --git a/smart-contracts/quasar/contracts/babylon-vault/schema/raw/response_to_owner.json b/smart-contracts/quasar/contracts/babylon-vault/schema/raw/response_to_owner.json new file mode 100644 index 000000000..06aee45c1 --- /dev/null +++ b/smart-contracts/quasar/contracts/babylon-vault/schema/raw/response_to_owner.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "OwnerResponse", + "description": "Returned from Owner.query()", + "type": "object", + "required": [ + "abolished", + "initialized" + ], + "properties": { + "abolished": { + "type": "boolean" + }, + "initialized": { + "type": "boolean" + }, + "owner": { + "type": [ + "string", + "null" + ] + }, + "proposed": { + "type": [ + "string", + "null" + ] + } + }, + "additionalProperties": false +} diff --git a/smart-contracts/quasar/contracts/babylon-vault/src/contract.rs b/smart-contracts/quasar/contracts/babylon-vault/src/contract.rs index 83a0e3b87..524d66dd3 100644 --- a/smart-contracts/quasar/contracts/babylon-vault/src/contract.rs +++ b/smart-contracts/quasar/contracts/babylon-vault/src/contract.rs @@ -1,8 +1,9 @@ use crate::error::VaultError; use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use crate::state::OWNER; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response}; +use cosmwasm_std::{to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response}; use cw2::set_contract_version; const CONTRACT_NAME: &str = "quasar:babylon-vault"; @@ -15,20 +16,31 @@ pub fn instantiate( deps: DepsMut, _env: Env, _info: MessageInfo, - _msg: InstantiateMsg, + msg: InstantiateMsg, ) -> VaultResult { + OWNER.initialize( + deps.storage, + deps.api, + mars_owner::OwnerInit::SetInitialOwner { owner: msg.owner }, + )?; set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; Ok(Response::default()) } #[cfg_attr(not(feature = "library"), entry_point)] -pub fn execute(_deps: DepsMut, _env: Env, _info: MessageInfo, _msg: ExecuteMsg) -> VaultResult { - Ok(Response::default()) +pub fn execute(deps: DepsMut, _env: Env, info: MessageInfo, msg: ExecuteMsg) -> VaultResult { + match msg { + ExecuteMsg::UpdateOwner(update) => Ok(OWNER.update(deps, info, update)?), + _ => Ok(Response::default()), + } } #[cfg_attr(not(feature = "library"), entry_point)] -pub fn query(_deps: Deps, _env: Env, _msg: QueryMsg) -> VaultResult { - Ok(Binary::default()) +pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> VaultResult { + match msg { + QueryMsg::Owner {} => Ok(to_json_binary(&OWNER.query(deps.storage)?)?), + _ => Ok(Binary::default()), + } } #[cfg(test)] diff --git a/smart-contracts/quasar/contracts/babylon-vault/src/error.rs b/smart-contracts/quasar/contracts/babylon-vault/src/error.rs index fde081039..4bb0c41c8 100644 --- a/smart-contracts/quasar/contracts/babylon-vault/src/error.rs +++ b/smart-contracts/quasar/contracts/babylon-vault/src/error.rs @@ -1,8 +1,12 @@ use cosmwasm_std::StdError; +use mars_owner::OwnerError; use thiserror::Error; #[derive(Error, Debug, PartialEq)] pub enum VaultError { #[error("{0}")] Std(#[from] StdError), + + #[error("{0}")] + Owner(#[from] OwnerError), } diff --git a/smart-contracts/quasar/contracts/babylon-vault/src/lib.rs b/smart-contracts/quasar/contracts/babylon-vault/src/lib.rs index a0cd84f22..79a621cd9 100644 --- a/smart-contracts/quasar/contracts/babylon-vault/src/lib.rs +++ b/smart-contracts/quasar/contracts/babylon-vault/src/lib.rs @@ -1,5 +1,6 @@ pub mod contract; mod error; pub mod msg; +pub mod state; pub use crate::error::VaultError; diff --git a/smart-contracts/quasar/contracts/babylon-vault/src/msg.rs b/smart-contracts/quasar/contracts/babylon-vault/src/msg.rs index 72bbb479d..f91a3421c 100644 --- a/smart-contracts/quasar/contracts/babylon-vault/src/msg.rs +++ b/smart-contracts/quasar/contracts/babylon-vault/src/msg.rs @@ -1,8 +1,11 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{Timestamp, Uint128}; +use mars_owner::{OwnerResponse, OwnerUpdate}; #[cw_serde] -pub struct InstantiateMsg {} +pub struct InstantiateMsg { + pub owner: String, +} #[cw_serde] pub enum ExecuteMsg { @@ -12,6 +15,7 @@ pub enum ExecuteMsg { Claim {}, // owner methods RegisterLst { denom: String }, + UpdateOwner(OwnerUpdate), } #[cw_serde] @@ -29,4 +33,6 @@ pub enum QueryMsg { Claimable { address: String }, #[returns(Uint128)] BalanceInUnderlying {}, + #[returns(OwnerResponse)] + Owner {}, } diff --git a/smart-contracts/quasar/contracts/babylon-vault/src/state.rs b/smart-contracts/quasar/contracts/babylon-vault/src/state.rs new file mode 100644 index 000000000..0c0e31ebd --- /dev/null +++ b/smart-contracts/quasar/contracts/babylon-vault/src/state.rs @@ -0,0 +1,3 @@ +use mars_owner::Owner; + +pub const OWNER: Owner = Owner::new("owner");