Skip to content

Commit

Permalink
Add owner (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
lubkoll committed Jul 25, 2024
1 parent 4476884 commit b5dc9ba
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 9 deletions.
1 change: 1 addition & 0 deletions smart-contracts/osmosis/Cargo.lock

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

14 changes: 14 additions & 0 deletions smart-contracts/quasar/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 smart-contracts/quasar/contracts/babylon-vault/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ cosmwasm-schema = { workspace = true }
cw-storage-plus = { workspace = true }
thiserror = { workspace = true }
cw2 = { workspace = true }
mars-owner = { workspace = true }
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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#",
Expand Down Expand Up @@ -132,6 +201,19 @@
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"owner"
],
"properties": {
"owner": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
}
]
},
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
]
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "InstantiateMsg",
"type": "object",
"required": [
"owner"
],
"properties": {
"owner": {
"type": "string"
}
},
"additionalProperties": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"owner"
],
"properties": {
"owner": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
}
]
}
Original file line number Diff line number Diff line change
@@ -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
}
24 changes: 18 additions & 6 deletions smart-contracts/quasar/contracts/babylon-vault/src/contract.rs
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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<Binary> {
Ok(Binary::default())
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> VaultResult<Binary> {
match msg {
QueryMsg::Owner {} => Ok(to_json_binary(&OWNER.query(deps.storage)?)?),
_ => Ok(Binary::default()),
}
}

#[cfg(test)]
Expand Down
4 changes: 4 additions & 0 deletions smart-contracts/quasar/contracts/babylon-vault/src/error.rs
Original file line number Diff line number Diff line change
@@ -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),
}
1 change: 1 addition & 0 deletions smart-contracts/quasar/contracts/babylon-vault/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod contract;
mod error;
pub mod msg;
pub mod state;

pub use crate::error::VaultError;
Loading

0 comments on commit b5dc9ba

Please sign in to comment.