Skip to content

Commit

Permalink
Merge pull request #212 from CosmWasm/update-to-0.4.0
Browse files Browse the repository at this point in the history
Update contract refs to v0.4.0
  • Loading branch information
ethanfrey committed Jan 7, 2021
2 parents b57edb7 + 9f17171 commit b42af06
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 38 deletions.
50 changes: 42 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ We are running a [public testnet](https://github.com/CosmWasm/testnets/blob/mast
you can use to test out any contracts.

**Warning** None of these contracts have been audited and no liability is
assumed for the use of any of this code. They are provided to turbo-start
assumed for the use of this code. They are provided to turbo-start
your projects.

**Note** All code in pre-1.0 packages is in "draft" form, meaning it may
Expand All @@ -59,7 +59,7 @@ cleaner (before: `expires: {at_height: {height: 12345}}` after

The most reusable components are the various cwXYZ specifications under
`packages`. Each one defines a standard interface for different domains,
eg. [cw20](./packages/cw20/README.md) for fungible tokens,
e.g. [cw20](./packages/cw20/README.md) for fungible tokens,
[cw721](./packages/cw721/README.md) for non-fungible tokens,
[cw1](./packages/cw1/README.md) for "proxy contracts", etc.
The interface comes with a human description in the READMEs, as well
Expand All @@ -79,7 +79,7 @@ or [create a pull request](https://github.com/CosmWasm/cosmwasm-plus/pulls) on t
## Contracts

We provide sample contracts that either implement or consume these
specifications to both provide examples, as well as provide a basis
specifications to both provide examples, and provide a basis
for code you can extend for more custom contacts, without worrying
about reinventing the wheel each time.
For example [`cw20-base`](./contracts/cw20-base) is a basic implementation
Expand All @@ -89,26 +89,61 @@ contract you want to build on it.
CW1 Proxy Contracts:

* [`cw1-whitelist`](./contracts/cw1-whitelist) a minimal implementation of `cw1`
mainly designed for reference
mainly designed for reference.
* [`cw1-subkeys`](./contracts/cw1-subkeys) a simple, but useful implementation,
which lets us use a proxy contract to provide "allowances" for native tokens
without modifying the `bank` module
without modifying the `bank` module.

CW3 Multisig:

* [`cw3-fixed-multisig`](./contracts/cw3-fixed-multisig) a simple implementation of the
[cw3 spec](./packages/cw3/README.md). It is a multisig with a fixed set of addresses,
created upon initialization.
Each address may have the same weight (K of N), or some may have extra voting
power. This works much like the native Cosmos SDK multisig, except that rather
than aggregating the signatures off chain and submitting the final result,
we aggregate the approvals on-chain.
* [`cw3-flex-multisig`](./contracts/cw3-flex-multisig) builds on cw3-fixed-multisig,
with a more powerful implementation of the cw3 spec. It's a multisig contract
backed by a cw4 (group) contract, which independently maintains the voter set.

CW4 Group:

* [`cw4-group`](./contracts/cw4-group) a basic implementation of the
[cw4 spec](./packages/cw4/README.md). It handles elected membership, by admin or multisig.
It fulfills all elements of the spec, including raw query lookups,
and is designed to be used as a backing storage for [cw3 compliant contracts](./packages/cw3/README.md).
* [`cw4-stake`](./contracts/cw4-stake) a second implementation of the
[cw4 spec](./packages/cw4/README.md). It fulfills all elements of the spec, including raw query lookups,
and is designed to be used as a backing storage for [cw3 compliant contracts](./packages/cw3/README.md).
It provides a similar API to [`cw4-group`], but rather than appointing members,
their membership and weight are based on the number of staked tokens they have.

CW20 Fungible Tokens:

* [`cw20-base`](./contracts/cw20-base) a straightforward, but complete
implementation of the cw20 spec along with all extensions. Can be deployed
as-is, or imported by other contracts
as-is, or imported by other contracts.
* [`cw20-atomic-swap`](./contracts/cw20-atomic-swap) an implementation of atomic swaps for
both native and cw20 tokens.
* [`cw20-bonding`](./contracts/cw20-bonding) a smart contract implementing arbitrary bonding curves,
which can use native and cw20 tokens as reserve tokens.
* [`cw20-staking`](./contracts/cw20-staking) provides staking derivatives,
staking native tokens on your behalf and minting cw20 tokens that can
be used to claim them. It uses `cw20-base` for all the cw20 logic and
only implements the interactions with the staking module and accounting
for prices
for prices.
* [`cw20-escrow`](./contracts/cw20-escrow) is a basic escrow contract
(arbiter can release or refund tokens) that is compatible with all native
and cw20 tokens. This is a good example to show how to interact with
cw20 tokens.

CW721 Non-fungible Tokens:

* [`cw721-base`](./contracts/cw721-base) a base implementation of a cw721 NFT contract.
It implements the [CW721 spec](./packages/cw721/README.md) and is designed to be deployed as is,
or imported into other contracts to easily build cw721-compatible NFTs with custom logic.

## Compiling

To compile all the contracts, run the following in the repo root:
Expand Down Expand Up @@ -143,4 +178,3 @@ Contracts that are "ready to deploy" may be licensed under AGPL 3.0 to
encourage anyone using them to contribute back any improvements they
make. This is common practice for actual projects running on Ethereum,
like Uniswap or Maker DAO.

4 changes: 2 additions & 2 deletions contracts/cw1-subkeys/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,10 @@ const CW1 = (client: SigningCosmWasmClient): CW1Contract => {

const upload = async (): Promise<number> => {
const meta = {
source: "https://github.com/CosmWasm/cosmwasm-plus/tree/v0.3.2/contracts/cw1-subkeys",
source: "https://github.com/CosmWasm/cosmwasm-plus/tree/v0.4.0/contracts/cw1-subkeys",
builder: "cosmwasm/rust-optimizer:0.10.7"
};
const sourceUrl = "https://github.com/CosmWasm/cosmwasm-plus/releases/download/v0.3.2/cw1_subkeys.wasm";
const sourceUrl = "https://github.com/CosmWasm/cosmwasm-plus/releases/download/v0.4.0/cw1_subkeys.wasm";
const wasm = await downloadWasm(sourceUrl);
const result = await client.upload(wasm, meta);
return result.codeId;
Expand Down
4 changes: 2 additions & 2 deletions contracts/cw20-base/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ const CW20 = (client: SigningCosmWasmClient): CW20Contract => {

const upload = async (): Promise<number> => {
const meta = {
source: "https://github.com/CosmWasm/cosmwasm-plus/tree/v0.3.2/contracts/cw20-base",
source: "https://github.com/CosmWasm/cosmwasm-plus/tree/v0.4.0/contracts/cw20-base",
builder: "cosmwasm/workspace-optimizer:0.10.7"
};
const sourceUrl = "https://github.com/CosmWasm/cosmwasm-plus/releases/download/v0.3.2/cw20_base.wasm";
const sourceUrl = "https://github.com/CosmWasm/cosmwasm-plus/releases/download/v0.4.0/cw20_base.wasm";
const wasm = await downloadWasm(sourceUrl);
const result = await client.upload(wasm, meta);
return result.codeId;
Expand Down
6 changes: 3 additions & 3 deletions contracts/cw3-fixed-multisig/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is a simple implementation of the [cw3 spec](../../packages/cw3/README.md).
It is a multisig with a fixed set of addresses created upon initialization.
Each address may have the same weight (K of N) or some may have extra voting
Each address may have the same weight (K of N), or some may have extra voting
power. This works much like the native Cosmos SDK multisig, except that rather
than aggregating the signatures off chain and submitting the final result,
we aggregate the approvals on-chain.
Expand Down Expand Up @@ -39,7 +39,7 @@ Once a proposal is "Passed", anyone may submit an "Execute" message. This will
trigger the proposal to send all stored messages from the proposal and update
it's state to "Executed", so it cannot run again. (Note if the execution fails
for any reason - out of gas, insufficient funds, etc - the state update will
be reverted and it will remain "Passed" so you can try again).
be reverted, and it will remain "Passed", so you can try again).

Once a proposal has expired without passing, anyone can submit a "Close"
message to mark it closed. This has no effect beyond cleaning up the UI/database.
Expand All @@ -62,4 +62,4 @@ sha256sum cw3_fixed_multisig.wasm
```

Or for a production-ready (optimized) build, run a build command in the
the repository root: https://github.com/CosmWasm/cosmwasm-plus#compiling.
repository root: https://github.com/CosmWasm/cosmwasm-plus#compiling.
22 changes: 11 additions & 11 deletions contracts/cw3-flex-multisig/README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# CW3 Flexible Multisig

This builds on [cw3-fixed-multisig](../cw3-fixed-multisig) with a more
This builds on [cw3-fixed-multisig](../cw3-fixed-multisig) with a more
powerful implementation of the [cw3 spec](../../packages/cw3/README.md).
It is a multisig contract that is backed by a
It is a multisig contract that is backed by a
[cw4 (group)](../../packages/cw4/README.md) contract, which independently
maintains the voter set.

This provides 2 main advantages:

* You can create two different multisigs with different voting thresholds
backed by the same group. Thus, you can have a 50% vote and a 67% vote
backed by the same group. Thus, you can have a 50% vote, and a 67% vote
that always use the same voter set, but can take other actions.
* TODO: It allows dynamic multisig groups. Since the group can change,
we can set one of the multisigs as the admin of the group contract,
and the


Besides the dynamic voting set, the main difference with the native
Cosmos SDK multisig, is that it aggregates the signatures on chain with
In addition to the dynamic voting set, the main difference with the native
Cosmos SDK multisig, is that it aggregates the signatures on chain, with
visible proposals (like `x/gov` in the Cosmos SDK), rather than requiring
signers to share signatures off chain.

Expand All @@ -26,10 +26,10 @@ signers to share signatures off chain.
The first step to create such a multisig is to instantiate a cw4 contract
with the desired member set. For now, this only is supported by
[cw4-group](../cw4-group), but we will add a token-weighted group contract
(TODO).
(TODO).

If you create a `cw4-group` contract and want a multisig to be able
to modify it's own group, do the following in multiple transactions:
to modify its own group, do the following in multiple transactions:

* init cw4-group, with your personal key as admin
* init a multisig pointing to the group
Expand All @@ -41,7 +41,7 @@ and depends on an external driver (hard to impossible to script such a
self-deploying contract on-chain). (TODO: document better).

When creating the multisig, you must set the required weight to pass a vote
as well as the max/default voting period. (TODO: allow more threshold types)
as well as the max/default voting period. (TODO: allow more threshold types)

## Handle Process

Expand All @@ -59,7 +59,7 @@ Once a proposal is "Passed", anyone may submit an "Execute" message. This will
trigger the proposal to send all stored messages from the proposal and update
it's state to "Executed", so it cannot run again. (Note if the execution fails
for any reason - out of gas, insufficient funds, etc - the state update will
be reverted and it will remain "Passed" so you can try again).
be reverted, and it will remain "Passed", so you can try again).

Once a proposal has expired without passing, anyone can submit a "Close"
message to mark it closed. This has no effect beyond cleaning up the UI/database.
Expand All @@ -72,7 +72,7 @@ open, this will calculate incorrect values (future PR).

You will need Rust 1.44.1+ with `wasm32-unknown-unknown` target installed.

You can run unit tests on this via:
You can run unit tests on this via:

`cargo test`

Expand All @@ -85,5 +85,5 @@ ls -l cw3_fixed_multisig.wasm
sha256sum cw3_fixed_multisig.wasm
```

Or for a production-ready (optimized) build, run a build command in the
Or for a production-ready (optimized) build, run a build command in
the repository root: https://github.com/CosmWasm/cosmwasm-plus#compiling.
12 changes: 6 additions & 6 deletions contracts/cw4-group/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# CW4 Group

This is a basic implementation of the [cw4 spec](../../packages/cw4/README.md).
It fufills all elements of the spec, including the raw query lookups,
and it designed to be used as a backing storage for
It fulfills all elements of the spec, including the raw query lookups,
and it designed to be used as a backing storage for
[cw3 compliant contracts](../../packages/cw3/README.md).

It stores a set of members along with an admin, and allows the admin to
update the state. Raw queries (intended for cross-contract queries)
update the state. Raw queries (intended for cross-contract queries)
can check a given member address and the total weight. Smart queries (designed
for client API) can do the same, and also query the admin address as well as
paginate over all members.
Expand Down Expand Up @@ -34,18 +34,18 @@ and stored under their `CanonicalAddr`, in a format defined in

Note that 0 *is an allowed weight*. This doesn't give any voting rights, but
it does define this address is part of the group. This could be used in
eg. a KYC whitelist to say they are allowed, but cannot participate in
e.g. a KYC whitelist to say they are allowed, but cannot participate in
decision-making.

## Messages

Basic update messages, queries, and hooks are defined by the
Basic update messages, queries, and hooks are defined by the
[cw4 spec](../../packages/cw4/README.md). Please refer to it for more info.

`cw4-group` adds one message to control the group membership:

`UpdateMembers{add, remove}` - takes a membership diff and adds/updates the
members, as well as removing any provided addresses. If an address is on both
lists, it will be removed. If it appears multiple times in `add`, only the
last occurance will be used.
last occurrence will be used.

6 changes: 3 additions & 3 deletions contracts/cw4-stake/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# CW4 Stake

This is a second implementation of the [cw4 spec](../../packages/cw4/README.md).
It fufills all elements of the spec, including the raw query lookups,
and it is designed to be used as a backing storage for
It fulfills all elements of the spec, including the raw query lookups,
and is designed to be used as a backing storage for
[cw3 compliant contracts](../../packages/cw3/README.md).

It provides a similar API to [`cw4-group`] (which handles elected membership),
but rather than appointing members (by admin or multisig), their
membership and weight is based on the number of tokens they have staked.
membership and weight are based on the number of tokens they have staked.
This is similar to many DAOs.

Only one denom can be bonded with both `min_bond` as the minimum amount
Expand Down
6 changes: 3 additions & 3 deletions contracts/cw721-base/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,10 @@ const CW721 = (client: SigningCosmWasmClient): CW721Contract => {

const upload = async (): Promise<number> => {
const meta = {
source: "https://github.com/CosmWasm/cosmwasm-plus/tree/v0.3.2/contracts/cw721-base",
builder: "cosmwasm/workspace-optimizer:0.10.4"
source: "https://github.com/CosmWasm/cosmwasm-plus/tree/v0.4.0/contracts/cw721-base",
builder: "cosmwasm/workspace-optimizer:0.10.7"
};
const sourceUrl = "https://github.com/CosmWasm/cosmwasm-plus/releases/download/v0.3.2/cw721_base.wasm";
const sourceUrl = "https://github.com/CosmWasm/cosmwasm-plus/releases/download/v0.4.0/cw721_base.wasm";
const wasm = await downloadWasm(sourceUrl);
const result = await client.upload(wasm, meta);
return result.codeId;
Expand Down

0 comments on commit b42af06

Please sign in to comment.