Skip to content

Commit

Permalink
Add vault share token (#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
lubkoll committed Aug 1, 2024
1 parent 975aae6 commit f6de0ac
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 140 deletions.
2 changes: 2 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.

4 changes: 4 additions & 0 deletions smart-contracts/quasar/contracts/babylon-vault/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ cw-storage-plus = { workspace = true }
thiserror = { workspace = true }
cw2 = { workspace = true }
mars-owner = { workspace = true }
quasar-std = { workspace = true }

[dev-dependencies]
prost = { workspace = true }
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
"title": "InstantiateMsg",
"type": "object",
"required": [
"owner"
"owner",
"subdenom"
],
"properties": {
"owner": {
"type": "string"
},
"subdenom": {
"type": "string"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -175,19 +179,11 @@
{
"type": "object",
"required": [
"pending"
"value"
],
"properties": {
"pending": {
"value": {
"type": "object",
"required": [
"address"
],
"properties": {
"address": {
"type": "string"
}
},
"additionalProperties": false
}
},
Expand All @@ -196,31 +192,10 @@
{
"type": "object",
"required": [
"claimable"
],
"properties": {
"claimable": {
"type": "object",
"required": [
"address"
],
"properties": {
"address": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"balance_in_underlying"
"owner"
],
"properties": {
"balance_in_underlying": {
"owner": {
"type": "object",
"additionalProperties": false
}
Expand All @@ -230,10 +205,10 @@
{
"type": "object",
"required": [
"owner"
"lsts"
],
"properties": {
"owner": {
"lsts": {
"type": "object",
"additionalProperties": false
}
Expand All @@ -243,10 +218,10 @@
{
"type": "object",
"required": [
"lsts"
"denom"
],
"properties": {
"lsts": {
"denom": {
"type": "object",
"additionalProperties": false
}
Expand All @@ -258,16 +233,9 @@
"migrate": null,
"sudo": null,
"responses": {
"balance_in_underlying": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Uint128",
"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"
},
"claimable": {
"denom": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Uint128",
"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); ```",
"title": "String",
"type": "string"
},
"lsts": {
Expand Down Expand Up @@ -327,47 +295,11 @@
},
"additionalProperties": false
},
"pending": {
"value": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Array_of_Claim",
"type": "array",
"items": {
"$ref": "#/definitions/Claim"
},
"definitions": {
"Claim": {
"type": "object",
"required": [
"amount",
"expiration"
],
"properties": {
"amount": {
"$ref": "#/definitions/Uint128"
},
"expiration": {
"$ref": "#/definitions/Timestamp"
}
},
"additionalProperties": false
},
"Timestamp": {
"description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```",
"allOf": [
{
"$ref": "#/definitions/Uint64"
}
]
},
"Uint128": {
"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"
},
"Uint64": {
"description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```",
"type": "string"
}
}
"title": "Uint128",
"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"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
"title": "InstantiateMsg",
"type": "object",
"required": [
"owner"
"owner",
"subdenom"
],
"properties": {
"owner": {
"type": "string"
},
"subdenom": {
"type": "string"
}
},
"additionalProperties": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,11 @@
{
"type": "object",
"required": [
"pending"
"value"
],
"properties": {
"pending": {
"value": {
"type": "object",
"required": [
"address"
],
"properties": {
"address": {
"type": "string"
}
},
"additionalProperties": false
}
},
Expand All @@ -26,31 +18,10 @@
{
"type": "object",
"required": [
"claimable"
],
"properties": {
"claimable": {
"type": "object",
"required": [
"address"
],
"properties": {
"address": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"balance_in_underlying"
"owner"
],
"properties": {
"balance_in_underlying": {
"owner": {
"type": "object",
"additionalProperties": false
}
Expand All @@ -60,10 +31,10 @@
{
"type": "object",
"required": [
"owner"
"lsts"
],
"properties": {
"owner": {
"lsts": {
"type": "object",
"additionalProperties": false
}
Expand All @@ -73,10 +44,10 @@
{
"type": "object",
"required": [
"lsts"
"denom"
],
"properties": {
"lsts": {
"denom": {
"type": "object",
"additionalProperties": false
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "String",
"type": "string"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Uint128",
"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"
}
32 changes: 28 additions & 4 deletions smart-contracts/quasar/contracts/babylon-vault/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
use crate::error::VaultError;
use crate::msg::{ExecuteMsg, InstantiateMsg, LstInfo, QueryMsg};
use crate::state::{LSTS, OWNER};
use crate::state::{LSTS, OWNER, VAULT_DENOM};
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_json_binary, Addr, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult,
to_json_binary, Addr, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult,
SubMsg,
};
use cw2::set_contract_version;
use quasar_std::quasarlabs::quasarnode::tokenfactory::v1beta1::{
MsgCreateDenom, MsgCreateDenomResponse,
};

const CONTRACT_NAME: &str = "quasar:babylon-vault";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

pub type VaultResult<T = Response> = Result<T, VaultError>;

pub(crate) const CREATE_DENOM_REPLY_ID: u64 = 1;

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
_env: Env,
env: Env,
_info: MessageInfo,
msg: InstantiateMsg,
) -> VaultResult {
Expand All @@ -26,7 +32,24 @@ pub fn instantiate(
mars_owner::OwnerInit::SetInitialOwner { owner: msg.owner },
)?;
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
Ok(Response::default())
let msg = MsgCreateDenom {
sender: env.contract.address.to_string(),
subdenom: msg.subdenom,
};
Ok(Response::new().add_submessage(SubMsg::reply_on_success(msg, CREATE_DENOM_REPLY_ID)))
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn reply(deps: DepsMut, _env: Env, reply: Reply) -> VaultResult {
match reply.id {
CREATE_DENOM_REPLY_ID => {
let response: MsgCreateDenomResponse = reply.result.try_into()?;
VAULT_DENOM.save(deps.storage, &response.new_token_denom)?;

Ok(Response::new().add_attribute("vault_denom", response.new_token_denom))
}
_ => unimplemented!(),
}
}

#[cfg_attr(not(feature = "library"), entry_point)]
Expand Down Expand Up @@ -61,6 +84,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> VaultResult<Binary> {
match msg {
QueryMsg::Owner {} => Ok(to_json_binary(&OWNER.query(deps.storage)?)?),
QueryMsg::Lsts {} => Ok(to_json_binary(&query_lsts(deps)?)?),
QueryMsg::Denom {} => Ok(to_json_binary(&VAULT_DENOM.load(deps.storage)?)?),
_ => Ok(Binary::default()),
}
}
Expand Down
9 changes: 4 additions & 5 deletions smart-contracts/quasar/contracts/babylon-vault/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use mars_owner::{OwnerResponse, OwnerUpdate};
#[cw_serde]
pub struct InstantiateMsg {
pub owner: String,
pub subdenom: String,
}

#[cw_serde]
Expand Down Expand Up @@ -34,14 +35,12 @@ pub struct LstInfo {
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
#[returns(Vec<Claim>)]
Pending { address: String },
#[returns(Uint128)]
Claimable { address: String },
#[returns(Uint128)]
BalanceInUnderlying {},
Value {},
#[returns(OwnerResponse)]
Owner {},
#[returns(Vec<LstInfo>)]
Lsts {},
#[returns(String)]
Denom {},
}
Loading

0 comments on commit f6de0ac

Please sign in to comment.