-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from CosmWasm/cw20-escrow
Cw20 escrow
- Loading branch information
Showing
20 changed files
with
1,483 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[alias] | ||
wasm = "build --release --target wasm32-unknown-unknown" | ||
wasm-debug = "build --target wasm32-unknown-unknown" | ||
unit-test = "test --lib --features backtraces" | ||
integration-test = "test --test integration" | ||
schema = "run --example schema" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[package] | ||
name = "cw20-escrow" | ||
version = "0.1.0" | ||
authors = ["Ethan Frey <ethanfrey@users.noreply.github.com>"] | ||
edition = "2018" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[features] | ||
backtraces = ["cosmwasm-std/backtraces"] | ||
|
||
[dependencies] | ||
cw20 = { path = "../../packages/cw20", version = "0.1.0" } | ||
cosmwasm-std = { version = "0.9.1", features = ["iterator"] } | ||
cosmwasm-storage = { version = "0.9.1", features = ["iterator"] } | ||
schemars = "0.7" | ||
serde = { version = "1.0.103", default-features = false, features = ["derive"] } | ||
snafu = { version = "0.6.3" } | ||
|
||
[dev-dependencies] | ||
cosmwasm-schema = { version = "0.9.1" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
CosmWasm-Plus: A collection of production-quality CosmWasm contracts | ||
Copyright (C) 2020 Confio OÜ | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as | ||
published by the Free Software Foundation, either version 3 of the | ||
License, or (at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
|
||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# CW20 Escrow | ||
|
||
This is an escrow meta-contract that allows multiple users to | ||
create independent escrows. Each escrow has a sender, recipient, | ||
and arbiter. It also has a unique id (for future calls to reference it) | ||
and an optional timeout. | ||
|
||
The basic function is the sender creates an escrow with funds. | ||
The arbiter may at any time decide to release the funds to either | ||
the intended recipient or the original sender (but no one else), | ||
and if it passes with optional timeout, anyone can refund the locked | ||
tokens to the original sender. | ||
|
||
We also add a function called "top_up", which allows anyone to add more | ||
funds to the contract at any time. | ||
|
||
## Token types | ||
|
||
This contract is meant not just to be functional, but also to work as a simple | ||
example of an CW20 "Receiver". And demonstrate how the same calls can be fed | ||
native tokens (via typical `HandleMsg` route), or cw20 tokens (via `Receiver` interface). | ||
|
||
Both `create` and `top_up` can be called directly (with a payload of native tokens), | ||
or from a cw20 contract using the [Receiver Interface](../../packages/cw20/README.md#receiver). | ||
This means we can load the escrow with any number of native or cw20 tokens (or a mix), | ||
allow of which get released when the arbiter decides. | ||
|
||
## Running this contract | ||
|
||
You will need Rust 1.41+ with `wasm32-unknown-unknown` target installed. | ||
|
||
You can run unit tests on this via: | ||
|
||
`cargo test` | ||
|
||
Once you are happy with the content, you can compile it to wasm via: | ||
|
||
``` | ||
RUSTFLAGS='-C link-arg=-s' cargo wasm | ||
cp ../../target/wasm32-unknown-unknown/release/cw20_escrow.wasm . | ||
ls -l cw20_escrow.wasm | ||
sha256sum cw20_escrow.wasm | ||
``` | ||
|
||
Or for a production-ready (compressed) build, run the following from the | ||
repository root (not currently working with this monorepo...) | ||
|
||
``` | ||
docker run --rm -v "$(pwd)":/code \ | ||
--mount type=volume,source="cosmwasm_plus_cache",target=/code/target \ | ||
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ | ||
cosmwasm/rust-optimizer:0.8.0 ./contracts/cw20-base | ||
mv contract.wasm cw20_escrow.wasm | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use std::env::current_dir; | ||
use std::fs::create_dir_all; | ||
|
||
use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; | ||
|
||
use cw20_escrow::msg::{DetailsResponse, HandleMsg, InitMsg, ListResponse, QueryMsg, ReceiveMsg}; | ||
|
||
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!(InitMsg), &out_dir); | ||
export_schema(&schema_for!(HandleMsg), &out_dir); | ||
export_schema(&schema_for!(QueryMsg), &out_dir); | ||
export_schema(&schema_for!(ReceiveMsg), &out_dir); | ||
export_schema(&schema_for!(DetailsResponse), &out_dir); | ||
export_schema(&schema_for!(ListResponse), &out_dir); | ||
} |
Oops, something went wrong.