Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Athena Consulting has been awarded a grant by [Atom Accelerator DAO](https://www
- [TimeLock Contract](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/timelock)
- [Crowdfunding Contract](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/crowdfunding)
- [Token Vault](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/token-vault)
- [Dead Man Switch Vault](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/deadman-switch-vault)

### :three: Complex Applications
- [Constant Product AMM](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/constant-product-amm)
Expand Down
40 changes: 40 additions & 0 deletions deadman-switch-vault/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[package]
name = "deadman-switch-vault"
version = "0.1.0"
authors = ["roemerw"]
edition = "2021"

exclude = [
"contract.wasm",
"hash.txt",
]

[lib]
crate-type = ["cdylib", "rlib"]

[profile.release]
opt-level = 3
debug = false
rpath = false
lto = true
debug-assertions = false
codegen-units = 1
panic = 'abort'
incremental = false
overflow-checks = true

[features]
backtraces = ["cosmwasm-std/backtraces"]
library = []

[dependencies]
cosmwasm-schema = "1.1.3"
cosmwasm-std = "1.1.3"
cw-storage-plus = "1.0.1"
cw2 = "1.0.1"
schemars = "0.8.10"
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
thiserror = "1.0.31"

[dev-dependencies]
cw-multi-test = "0.16.2"
93 changes: 93 additions & 0 deletions deadman-switch-vault/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Dead Man Switch Vault

The Dead Man Switch Vault contract demonstrates a simple inheritance-style native token vault. An owner keeps the vault alive by calling `Heartbeat`. If the owner misses the configured block-height window, the configured beneficiary can claim the contract's balance in the configured native denom.

This example demonstrates:

- owner and beneficiary authorization checks
- block-height based liveness windows
- receiving native funds with an execute message
- sending native funds from a contract with `BankMsg::Send`
- querying contract status without changing state

## Instantiate

```json
{
"owner": "cosmos1owner...",
"beneficiary": "cosmos1beneficiary...",
"denom": "uatom",
"heartbeat_window": 10000
}
```

`owner` is optional. If omitted, the instantiator becomes the owner.

## Execute

### Deposit

```json
{
"deposit": {}
}
```

Attach native tokens in the configured denom. Anyone can deposit.

### Heartbeat

```json
{
"heartbeat": {}
}
```

Only the owner can call this. It updates the last heartbeat height to the current block height.

### Update Config

```json
{
"update_config": {
"owner": "cosmos1newowner...",
"beneficiary": "cosmos1newbeneficiary...",
"heartbeat_window": 20000
}
}
```

Only the owner can call this. Every field is optional.

### Claim

```json
{
"claim": {
"recipient": "cosmos1recipient...",
"amount": "250000"
}
}
```

Only the beneficiary can claim, and only after the heartbeat window has expired. `recipient` and `amount` are optional. If no recipient is provided, funds go to the beneficiary. If no amount is provided, the whole contract balance for the configured denom is claimed.

## Query

### Config

```json
{
"config": {}
}
```

### Status

```json
{
"status": {}
}
```

Returns the owner, beneficiary, configured denom, heartbeat window, last heartbeat height, expiration height, and whether the vault is currently expired.
11 changes: 11 additions & 0 deletions deadman-switch-vault/src/bin/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use cosmwasm_schema::write_api;

use deadman_switch_vault::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};

fn main() {
write_api! {
instantiate: InstantiateMsg,
execute: ExecuteMsg,
query: QueryMsg,
}
}
Loading