Code Monkey home page Code Monkey logo

hackatom's Introduction

CW20 Clawback

This is a prototype contract code for "clawbacks" of native and CW20 tokens. A clawback works as follows:

  • There is a "holder" key/account, a "backup" key/account, and a "clawback period" (which determines when the clawback expires).
  • Within a "clawback period", "holder" can transfer to "holders" / other clawbacks (provided their terms match the outgoing contract: they have the same "backup", "clawback period" is at least as long, and they support the same tokens) or refresh the clawback duration. After the clawback period expires, "holder" can withdraw the tokens.
  • Within a "clawback period", "backup" can transfer to other holder, refresh the clawback duration or burn the tokens / destroy the contract.

There are at least two potential use cases of this logic:

  1. Exchange hot/cold wallet management protocols (similar to Bitcoin Vaults with covenants): the "backup" key here is used for retrieving back (or destroying if the "backup" key leaked too) stolen funds.
  2. Cashbacks: the "backup" key here roughly corresponds to the issuer / payment processor which serves merchants (that are paid in fiat) and gives cashbacks to customers -- if customer order are cancelled, modified or goods are returned, full or partial cashbacks are taken back.

See this simplified explanation in Google Slides.

Running this contract

You will need Rust 1.44.1+ 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_clawback.wasm .
ls -l cw20_clawback.wasm
sha256sum cw20_clawback.wasm

Or for a production-ready (optimized) build, run a build command, as suggested in CosmWasm:

docker run --rm -v "$(pwd)":/code \
  --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
  --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
  cosmwasm/rust-optimizer:0.9.0

HackAtom Testnet

The optimized binary was uploaded to the HackAtom testnet (running on 0.11.1 CosmWasm) and got the id 28, so you can just use it without re-uploading it:

wasmcli tx wasm instantiate 28 "{}" --from <YOUR KEY> --label "<SOME LABEL>" --gas 100000 -y

wasmcli tx wasm execute <INSTANTIATED-CONTRACT-ADDRESS> '{"create": {"id": "<ID>", "backup": "<ADDR1>", "holder": "<ADDR2>", "clawback_period": <TIME>}}' --from <YOUR KEY> --gas 100000 --amount=<SOME AMOUNT>ucosm -y

wasmcli tx wasm execute <INSTANTIATED-CONTRACT-ADDRESS> '{"withdraw": {"id": "<ID>"}}' --from <KEY FOR ADDR2> --gas 100000 -y

...

hackatom's People

Contributors

tomtau avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.