Skip to content

Commit

Permalink
Merge branch 'version/1.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDeeKay committed Dec 12, 2023
2 parents 6d736c0 + 1a7c965 commit ccaffb3
Show file tree
Hide file tree
Showing 346 changed files with 19,168 additions and 11,072 deletions.
Binary file added artifacts/cw20_base-aarch64.wasm
Binary file not shown.
Binary file added artifacts/cw20_base.wasm
Binary file not shown.
Binary file added artifacts/cw3_fixed_multisig-aarch64.wasm
Binary file not shown.
Binary file added artifacts/cw3_fixed_multisig.wasm
Binary file not shown.
Binary file added artifacts/cw721_base-aarch64.wasm
Binary file not shown.
Binary file added artifacts/cw721_base.wasm
Binary file not shown.
Binary file added artifacts/cw721_metadata_onchain-aarch64.wasm
Binary file not shown.
Binary file added artifacts/cw721_metadata_onchain.wasm
Binary file not shown.
4 changes: 4 additions & 0 deletions contracts/attestation/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[alias]
wasm = "build --release --target wasm32-unknown-unknown"
unit-test = "test --lib"
schema = "run --example schema"
43 changes: 43 additions & 0 deletions contracts/attestation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "attestation"
version = "1.0.0"
authors = ["Terra Money <[email protected]>"]
edition = "2021"

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]
default = ["contract"]

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

[package.metadata.scripts]
optimize = """docker run --rm -v "${process.cwd()}":/code \
-v "${path.join(process.cwd(), "../../", "packages")}":/packages \
--mount type=volume,source="${contract}_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/rust-optimizer${process.env.TERRARIUM_ARCH_ARM64 ? "-arm64" : ""}:0.12.6
"""

[dependencies]
common = { path = "../../packages/common" }
cosmwasm-schema = "1"
cosmwasm-std = "1"
cw-storage-plus = "1.0.1"
cw2 = "1.0.1"
attestation-api = { path = "../../packages/attestation-api" }

[dev-dependencies]
8 changes: 8 additions & 0 deletions contracts/attestation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Attestation contract

A contract representing an attestation signed by users.

Contains (possibly markup-containing) text of the attestation.
Also stores each user's individual state of attestation signature (knows whether a user signed the attestation or not).

Used by other Enterprise contracts to determine whether a user has access to certain DAO functionalities.
19 changes: 19 additions & 0 deletions contracts/attestation/examples/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::{env::current_dir, fs::create_dir_all};

use attestation_api::api::{AttestationTextResponse, HasUserSignedResponse};
use attestation_api::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
use cosmwasm_schema::{export_schema, remove_schemas, schema_for};

fn main() {
let mut out_dir = current_dir().unwrap();
out_dir.push("schema");
create_dir_all(&out_dir).unwrap();
remove_schemas(&out_dir).unwrap();

export_schema(&schema_for!(InstantiateMsg), &out_dir);
export_schema(&schema_for!(ExecuteMsg), &out_dir);
export_schema(&schema_for!(QueryMsg), &out_dir);
export_schema(&schema_for!(MigrateMsg), &out_dir);
export_schema(&schema_for!(AttestationTextResponse), &out_dir);
export_schema(&schema_for!(HasUserSignedResponse), &out_dir);
}
92 changes: 92 additions & 0 deletions contracts/attestation/src/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
use crate::state::{ATTESTATION_TEXT, USER_SIGNATURES};
use attestation_api::api::{AttestationTextResponse, HasUserSignedParams, HasUserSignedResponse};
use attestation_api::error::AttestationResult;
use attestation_api::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
use attestation_api::response::{execute_sign_response, instantiate_response};
use common::cw::{Context, QueryContext};
use cosmwasm_std::{
entry_point, to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response,
};
use cw2::set_contract_version;

// version info for migration info
const CONTRACT_NAME: &str = "crates.io:attestation";
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,
) -> AttestationResult<Response> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

ATTESTATION_TEXT.save(deps.storage, &msg.attestation_text)?;

Ok(instantiate_response())
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
deps: DepsMut,
env: Env,
info: MessageInfo,
msg: ExecuteMsg,
) -> AttestationResult<Response> {
let ctx = &mut Context { deps, env, info };

match msg {
ExecuteMsg::SignAttestation {} => sign_attestation(ctx),
}
}

fn sign_attestation(ctx: &mut Context) -> AttestationResult<Response> {
USER_SIGNATURES.save(ctx.deps.storage, ctx.info.sender.clone(), &())?;

// TODO: report this change somehow to funds distributor and/or governance controller
Ok(execute_sign_response(ctx.info.sender.to_string()))
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn reply(_deps: DepsMut, _env: Env, _msg: Reply) -> AttestationResult<Response> {
Ok(Response::new())
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> AttestationResult<Binary> {
let qctx = QueryContext { deps, env };

let response = match msg {
QueryMsg::AttestationText {} => to_json_binary(&query_attestation_text(qctx)?)?,
QueryMsg::HasUserSigned(params) => to_json_binary(&query_has_user_signed(qctx, params)?)?,
};

Ok(response)
}

fn query_attestation_text(qctx: QueryContext) -> AttestationResult<AttestationTextResponse> {
let attestation_text = ATTESTATION_TEXT.load(qctx.deps.storage)?;

Ok(AttestationTextResponse {
text: attestation_text,
})
}

fn query_has_user_signed(
qctx: QueryContext,
params: HasUserSignedParams,
) -> AttestationResult<HasUserSignedResponse> {
let user = qctx.deps.api.addr_validate(&params.user)?;

let has_signed = USER_SIGNATURES.has(qctx.deps.storage, user);

Ok(HasUserSignedResponse { has_signed })
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> AttestationResult<Response> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

Ok(Response::new().add_attribute("action", "migrate"))
}
7 changes: 7 additions & 0 deletions contracts/attestation/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extern crate core;

pub mod contract;
pub mod state;

#[cfg(test)]
mod tests;
6 changes: 6 additions & 0 deletions contracts/attestation/src/state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use cosmwasm_std::Addr;
use cw_storage_plus::{Item, Map};

pub const ATTESTATION_TEXT: Item<String> = Item::new("attestation_text");

pub const USER_SIGNATURES: Map<Addr, ()> = Map::new("user_signatures");
1 change: 1 addition & 0 deletions contracts/attestation/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod unit;
1 change: 1 addition & 0 deletions contracts/attestation/src/tests/unit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

4 changes: 4 additions & 0 deletions contracts/denom-staking-membership/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[alias]
wasm = "build --release --target wasm32-unknown-unknown"
unit-test = "test --lib"
schema = "run --example schema"
45 changes: 45 additions & 0 deletions contracts/denom-staking-membership/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[package]
name = "denom-staking-membership"
version = "1.0.0"
authors = ["Terra Money <[email protected]>"]
edition = "2021"

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]
default = ["contract"]

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

[package.metadata.scripts]
optimize = """docker run --rm -v "${process.cwd()}":/code \
-v "${path.join(process.cwd(), "../../", "packages")}":/packages \
--mount type=volume,source="${contract}_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/rust-optimizer${process.env.TERRARIUM_ARCH_ARM64 ? "-arm64" : ""}:0.12.6
"""

[dependencies]
common = { path = "../../packages/common" }
membership-common-api = { path = "../../packages/membership-common-api" }
membership-common = { path = "../../packages/membership-common" }
cosmwasm-std = "1"
cw2 = "1.0.1"
denom-staking-api = { path = "../../packages/denom-staking-api" }
denom-staking-impl = { path = "../../packages/denom-staking-impl" }

[dev-dependencies]
cosmwasm-schema = "1.1.9"
9 changes: 9 additions & 0 deletions contracts/denom-staking-membership/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Denom staking membership

A contract for managing a denom (on-chain native assets) staking membership for an Enterprise DAO.
Essentially a proxy to the denom-staking library.

Mainly serves to:
- store users' denom stakes
- provide an interface to stake, unstake, and claim user denoms
- provide queries for user and total weights, and user claims
25 changes: 25 additions & 0 deletions contracts/denom-staking-membership/examples/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use std::{env::current_dir, fs::create_dir_all};

use cosmwasm_schema::{export_schema, remove_schemas, schema_for};
use denom_staking_api::api::ClaimsResponse;
use denom_staking_api::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
use membership_common_api::api::{
AdminResponse, MembersResponse, TotalWeightResponse, UserWeightResponse,
};

fn main() {
let mut out_dir = current_dir().unwrap();
out_dir.push("schema");
create_dir_all(&out_dir).unwrap();
remove_schemas(&out_dir).unwrap();

export_schema(&schema_for!(InstantiateMsg), &out_dir);
export_schema(&schema_for!(ExecuteMsg), &out_dir);
export_schema(&schema_for!(QueryMsg), &out_dir);
export_schema(&schema_for!(MigrateMsg), &out_dir);
export_schema(&schema_for!(AdminResponse), &out_dir);
export_schema(&schema_for!(MembersResponse), &out_dir);
export_schema(&schema_for!(TotalWeightResponse), &out_dir);
export_schema(&schema_for!(UserWeightResponse), &out_dir);
export_schema(&schema_for!(ClaimsResponse), &out_dir);
}
84 changes: 84 additions & 0 deletions contracts/denom-staking-membership/src/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
use common::cw::{Context, QueryContext};
use cosmwasm_std::{
entry_point, to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response,
};
use cw2::set_contract_version;
use denom_staking_api::error::DenomStakingResult;
use denom_staking_api::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
use denom_staking_impl::execute::{claim, stake_denom, unstake, update_unlocking_period};
use denom_staking_impl::query::{
query_claims, query_denom_config, query_members, query_releasable_claims, query_total_weight,
query_user_weight,
};
use membership_common::weight_change_hooks::{add_weight_change_hook, remove_weight_change_hook};

// version info for migration info
const CONTRACT_NAME: &str = "crates.io:denom-staking-membership";
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,
) -> DenomStakingResult<Response> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

let ctx = &mut Context { deps, env, info };

denom_staking_impl::instantiate::instantiate(ctx, msg)?;

Ok(Response::new().add_attribute("action", "instantiate"))
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
deps: DepsMut,
env: Env,
info: MessageInfo,
msg: ExecuteMsg,
) -> DenomStakingResult<Response> {
let ctx = &mut Context { deps, env, info };

let response = match msg {
ExecuteMsg::Unstake(msg) => unstake(ctx, msg)?,
ExecuteMsg::Claim(msg) => claim(ctx, msg)?,
ExecuteMsg::UpdateUnlockingPeriod(msg) => update_unlocking_period(ctx, msg)?,
ExecuteMsg::AddWeightChangeHook(msg) => add_weight_change_hook(ctx, msg)?,
ExecuteMsg::RemoveWeightChangeHook(msg) => remove_weight_change_hook(ctx, msg)?,
ExecuteMsg::Stake { user } => stake_denom(ctx, user)?,
};

Ok(response)
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn reply(_deps: DepsMut, _env: Env, _msg: Reply) -> DenomStakingResult<Response> {
Ok(Response::new())
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> DenomStakingResult<Binary> {
let qctx = QueryContext { deps, env };

let response = match msg {
QueryMsg::DenomConfig {} => to_json_binary(&query_denom_config(&qctx)?)?,
QueryMsg::UserWeight(params) => to_json_binary(&query_user_weight(&qctx, params)?)?,
QueryMsg::TotalWeight(params) => to_json_binary(&query_total_weight(&qctx, params)?)?,
QueryMsg::Claims(params) => to_json_binary(&query_claims(&qctx, params)?)?,
QueryMsg::ReleasableClaims(params) => {
to_json_binary(&query_releasable_claims(&qctx, params)?)?
}
QueryMsg::Members(params) => to_json_binary(&query_members(&qctx, params)?)?,
};

Ok(response)
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> DenomStakingResult<Response> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

Ok(Response::new().add_attribute("action", "migrate"))
}
6 changes: 6 additions & 0 deletions contracts/denom-staking-membership/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extern crate core;

pub mod contract;

#[cfg(test)]
mod tests;
1 change: 1 addition & 0 deletions contracts/denom-staking-membership/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod unit;
1 change: 1 addition & 0 deletions contracts/denom-staking-membership/src/tests/unit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

4 changes: 4 additions & 0 deletions contracts/enterprise-facade-v1/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[alias]
wasm = "build --release --target wasm32-unknown-unknown"
unit-test = "test --lib"
schema = "run --example schema"
Loading

0 comments on commit ccaffb3

Please sign in to comment.