Skip to content

Commit

Permalink
Add owner
Browse files Browse the repository at this point in the history
  • Loading branch information
lubkoll committed Jul 19, 2024
1 parent 0b883d0 commit b87d7bc
Show file tree
Hide file tree
Showing 14 changed files with 272 additions and 11 deletions.
1 change: 1 addition & 0 deletions smart-contracts/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/contracts/babylon-vault/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ cw-storage-plus = { workspace = true }
thiserror = { workspace = true }
cw2 = { workspace = true }
cw-orch = { workspace = true }
mars-owner = { workspace = true }
115 changes: 114 additions & 1 deletion smart-contracts/contracts/babylon-vault/schema/babylon-vault.json
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
63 changes: 62 additions & 1 deletion smart-contracts/contracts/babylon-vault/schema/raw/execute.json
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
}
13 changes: 13 additions & 0 deletions smart-contracts/contracts/babylon-vault/schema/raw/query.json
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/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,18 +16,29 @@ 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()),
}
}
4 changes: 4 additions & 0 deletions smart-contracts/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/contracts/babylon-vault/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod contract;
mod error;
pub mod msg;
pub mod state;

#[cfg(test)]
mod tests;
Expand Down
8 changes: 7 additions & 1 deletion smart-contracts/contracts/babylon-vault/src/msg.rs
Original file line number Diff line number Diff line change
@@ -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]
#[derive(cw_orch::ExecuteFns)]
Expand All @@ -16,6 +19,7 @@ pub enum ExecuteMsg {
RegisterLst {
denom: String,
},
UpdateOwner(OwnerUpdate),
}

#[cw_serde]
Expand All @@ -33,4 +37,6 @@ pub enum QueryMsg {
Claimable { address: String },
#[returns(Uint128)]
BalanceInUnderlying {},
#[returns(OwnerResponse)]
Owner {},
}
3 changes: 3 additions & 0 deletions smart-contracts/contracts/babylon-vault/src/state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use mars_owner::Owner;

pub const OWNER: Owner = Owner::new("owner");
Loading

0 comments on commit b87d7bc

Please sign in to comment.